|
uname -a
Linux nxgzserver 2.4.21-4.ELsmp #1 SMP Fri Oct 3 17:52:56 EDT 2003 i686 i686 i386 GNU/Linux
cc 1.c
1.c: In function `save2file':
1.c:64: warning: assignment makes pointer from integer without a cast
cat 1.c
#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;
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;
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;
}
fclose(fptr);
return;
} |
|