C语言问题。error C2143: 语法错误 : 缺少“;”(在“{”的前面),跪求解决

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();

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()函数的认识就是错误的。请查看该函数的说明。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-10-29
main函数貌似少了个括号。
第2个回答  2014-10-29
天啊,第一条错误指向了哪一行总得说清楚吧,不是要解答人数你的程序行数吧。vs可以显示行号的。