C语言问题。error C2143: 语法错误 : 缺少“;”(在“{”的前面),跪求解决 20
intmain(){structbook*phead=NULL,*ptemp,*prev;charfilename[50]="d:\\book.txt";FILE*pbo...
int main(){ struct book *phead = NULL, *ptemp, *prev; char filename[50] = "d:\\book.txt"; FILE *pbook; int i = 0; char ch, str[50];
if (pbook = fopen(filename, "r") == NULL) { printf("error in open file"); exit(0); }
while (!feof(pbook)) { ptemp = (struct book *)malloc(sizeof(struct book)); if (ptemp == NULL) { printf("error"); exit(0); }
if (phead == NULL) { printf("error in memory allocate"); exit(0); } else prev->next = ptemp; ptemp->next = NULL;
fgets(ptemp->num, 50, pbook); fgets(ptemp->bname, 50, pbook); fgets(ptemp->wname, 50, pbook); fgets(ptemp->press, 50, pbook); fgets(ptemp->sort, 50, pbook); fscanf(pbook, &ptemp->Ptime); fscanf(pbook, &ptemp->price);
prev = ptemp; }
//图书查询 void chaxun(struct book *head) { int a; printf(" ==========================================================\n"); printf(" ** 1-按图书编号查询 2-按图书名查询 **\n"); printf(" ** 3-按图书类别查询 4-按作者名查询 **\n"); printf(" ** 5-按出版时间查询 0-退出查询 **\n"); printf(" ==========================================================\n"); printf("请输入所选择的编号:"); scanf("%d", &a);
getchar(); 展开
if (pbook = fopen(filename, "r") == NULL) { printf("error in open file"); exit(0); }
while (!feof(pbook)) { ptemp = (struct book *)malloc(sizeof(struct book)); if (ptemp == NULL) { printf("error"); exit(0); }
if (phead == NULL) { printf("error in memory allocate"); exit(0); } else prev->next = ptemp; ptemp->next = NULL;
fgets(ptemp->num, 50, pbook); fgets(ptemp->bname, 50, pbook); fgets(ptemp->wname, 50, pbook); fgets(ptemp->press, 50, pbook); fgets(ptemp->sort, 50, pbook); fscanf(pbook, &ptemp->Ptime); fscanf(pbook, &ptemp->price);
prev = ptemp; }
//图书查询 void chaxun(struct book *head) { int a; printf(" ==========================================================\n"); printf(" ** 1-按图书编号查询 2-按图书名查询 **\n"); printf(" ** 3-按图书类别查询 4-按作者名查询 **\n"); printf(" ** 5-按出版时间查询 0-退出查询 **\n"); printf(" ==========================================================\n"); printf("请输入所选择的编号:"); scanf("%d", &a);
getchar(); 展开
展开全部
int main()
{
struct book *phead = NULL, *ptemp, *prev;
....
char ch, str[50];
if (pbook = fopen(filename, "r") == NULL)
{.... }
while (!feof(pbook))
{
ptemp = (struct book *)malloc(sizeof(struct book));
if (ptemp == NULL)
{ ....... }
if (phead == NULL)
{ ..... }
else
prev->next = ptemp;
...
prev = ptemp;
} //end while (!feof(pbook))
??end main
单从结构上看,main就少了一个}.
另外,从 fgets(ptemp->num, 50, pbook);来看,你对fgets()函数的认识就是错误的。请查看该函数的说明。
{
struct book *phead = NULL, *ptemp, *prev;
....
char ch, str[50];
if (pbook = fopen(filename, "r") == NULL)
{.... }
while (!feof(pbook))
{
ptemp = (struct book *)malloc(sizeof(struct book));
if (ptemp == NULL)
{ ....... }
if (phead == NULL)
{ ..... }
else
prev->next = ptemp;
...
prev = ptemp;
} //end while (!feof(pbook))
??end main
单从结构上看,main就少了一个}.
另外,从 fgets(ptemp->num, 50, pbook);来看,你对fgets()函数的认识就是错误的。请查看该函数的说明。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询