Code:
struct lib { char *name,*author,*publish; int price; int no; }u[50]; FILE *fp; void fin() //Inputs data to a file { int i; fp=fopen("abc.txt","w"); for(i=1;i<=n;i++) { fprintf(fp,"%s",&u[i].name); putc('\t',fp); fprintf(fp,"%s",&u[i].author); putc('\t',fp); fprintf(fp,"%s",&u[i].publish); putc('\t',fp); fprintf(fp,"%d",u[i].price); putc('\t',fp); fprintf(fp,"%d",u[i].no); putc('\n',fp); } fclose(fp); } void fout() // Reads data from the file { int i,x,j=0; char c,d[50]; d[0]='\0'; fp=fopen("abc.txt","r"); for(i=1;i<=n;i++) { fscanf(fp,"%s",u[i].name); while((c=getc(fp))!='\t') ; fscanf(fp,"%s",u[i].author); while((c=getc(fp))!='\t') ; fscanf(fp,"%s",u[i].publish); while((c=getc(fp))!='\t') ; fscanf(fp,"%d",&u[i].price); while((c=getc(fp))!='\t') ; fscanf(fp,"%d",&u[i].no); while((c=getc(fp))!='\n') ; } fclose(fp); }
The strings read from the file are not stored in the structure. If I try to display the strings they appear as <null> . The numbers are input without any problem.
Please help as soon as possible.
Comment