- 论坛徽章:
- 0
|
在linux下编写的shell怎么可以弄到xp下运行.
[quote]原帖由 "hellolinux"]关键我的C太菜了,兄弟能不能给一个代码,有回报的.[/quote 发表:
我写了一个,没调试。呵呵,输出格式一行一个发票号。看看吧,有问题咱们再讨论。回报什么的就不必了。
- #include <stdio.h>
- #include <malloc.h>
- #include <string.h>
- struct fapiao{
- char fp[30];
- struct fapiao *next;
- };
- typedef struct fapiao FAPIAO;
- main()
- {
- char fpstr[30];
- FAPIAO *head;
- void insert(FAPIAO **,char *);
- void save2file(FAPIAO **,char *);
- head=NULL;
- while (1) /*接受键盘输入,当输入"exit"时跳出循环,然后输入文件名,保存数据*/
- {
- printf("Please enter the fapiao serial number,exit program with string "exit":\n");
- scanf("%s",fpstr);
- if (strcmp(fpstr,"exit")==0) break;
- insert(&head,fpstr);
- }
- printf(Please enter the file name for save datas:\n");
- scanf("%s",fpstr);
- save2file(&head,fpstr);
- }
- void insert(FAPIAO **head,char *string)
- {
- FAPIAO *cur,*pre,*new;
-
- if ((new=(FAPIAO *)malloc(sizeof(FAPIAO)))==NULL)
- {printf("Can't creat new node!\n");return;}
- strcpy(new->fp,string);
- new->next=NULL;
- pre=*head;
- if (pre==NULL)
- *head=new;
- else
- {cur=pre->next;
- while(cur!=NULL)
- {if(strcmp(string,cur->fp)==0) /*判断是否重复*/
- {printf("Repeated!\n");return;}
- pre=cur; /*不重复,前移*/
- cur=cur->next;
- }
- pre->next=new; /*链接到表尾*/
- return;
- }
- }
- void save2file(FAPIAO **head,char *string)
- {
- FAPIAO *cur,*pre;
- FILE *fptr;
- pre=*head;
- if (pre==NULL) return;
- cur=pre->next;
- if ((fptr=fopen("string",w))==NULL)
- {printf("Can't creat file!\n");return;}
- while (cur!=NULL)
- {fprintf(fptr,"%30s\n",cur->fp); /*定义格式存数据*/
- *head=cur; /*移动头结点*/
- cur=cur->next; /*当前结点指针后移*/
- free(pre); /*释放存过的结点的内存*/
- pre=*head;/*给pre重新赋值,指向当前结点*/
- }
- return;
- }
复制代码 |
|