- 论坛徽章:
- 0
|
在linux下编写的shell怎么可以弄到xp下运行.
printf(" lease enter the fapiao serial number,exit program with string \"exit\":\n" ; 这行。
printf(" lease enter the file name for save datas:\n" ;这行
if (fptr=fopen("string","w" ==NULL)这行
再实验一下。
- #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)
- {
- 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;
- }
- return;
- }
复制代码 |
|