图书信息管理系统的一些问题
我定义了一个结构体数组来存储图书信息。图书信息的录入功能代码如下。问题1:想请问数据的存储方式是如何的,为什么我将它从文件读出的时候只能读出第一个呢(已经写了一个循环,待会将那段代码放到下面,希望大家能指正)
问题2:为什么我在调试的时候查看不到到图书的名字之类(就是字符类型的数据)的信息呢
诚心请教,谢谢!(在线等,挺急的。。)
图书信息录入功能的代码:
程序代码:
void book_login() { void adm_list(); int i=0; FILE *fp; char a; printf("\n\n\n\t ---Please enter book's information---\n\n"); printf("\tLogin ID:"); scanf("%d",&books[i].loginID); printf("\n\tBook name:"); scanf("%s",&books[i].bkname); printf("\n\tWriter's name:"); scanf("%s",&books[i].wname); printf("\n\tSort number:"); scanf("%d",&books[i].sortnum); printf("\n\tPublishing company:"); scanf("%s",&books[i].cbname); printf("\n\tPublishing time:"); scanf("%ld",&books[i].time); printf("\n\tBook's Price:"); scanf("%f",&books[i].price); system("cls"); if((fp=fopen("book.txt","r"))==NULL) { fp=fopen("book.txt","w"); } else { fclose(fp); fp=fopen("book.txt","a"); } fprintf(fp,"%d\t%s\t%s\t%d%\t%s\t%ld\t%f\n",books[i].loginID,books[i].bkname,books[i].wname,books[i].sortnum,books[i].cbname,books[i].time,books[i].price); fclose(fp); printf("\n\n\n\n\t The information has been stored,enter your choice to continue!\n\n"); printf("\n"); a=getchar(); adm_list(); fclose(fp); }
将图书数据从文件读出的部分代码
程序代码:
FILE *fp; fp=fopen("book.txt","r"); if(!fp) { printf ("\n\n\t\t\tThere is no file.\n\t\t\tCan not open this file!\n"); } while(!feof(fp)) { for(j=0;j<10;j++) { fscanf(fp,"%d",&books[i].loginID); fscanf(fp,"%s",&books[i].bkname); fscanf(fp,"%s",&books[i].wname); fscanf(fp,"%d",&books[i].sortnum); fscanf(fp,"%s",&books[i].cbname); fscanf(fp,"%ld",&books[i].time); fscanf(fp,"%f",&books[i].price); } } fclose(fp);