#include "stdio.h"
#include "stdlib.h"
#include "string.h"
struct listNode
{int num;
char name[20];
char sex;
int age;
int score[5];
struct listNode *next;
};
struct listNode *head, *tail;
void put_to_end(struct listNode *p)
{p->next=NULL;
if(head==NULL) head=p;
else tail->next=p;
tail=p;
}
void input_data()
{
int i;
char ch;
struct listNode *p;
while(1)
{
printf("\nInput data(Y/N):");
scanf("\n%c",&ch);
if(ch=='y'||ch=='Y')
{
p=malloc(sizeof(struct listNode));
printf("Input num:");
scanf("%d",&p->num);
printf("Input name:");
scanf("%s",&p->name);
printf("Input sex:");
scanf("%c",&p->sex);
printf("Input age:");
scanf("%d",&p->age);
printf("input 5 score:");
for(i=0;i<5;i++)
scanf("%d",&p->score[i]);
put_to_end(p);
}
else break;
}
}
void FDname()
{ int i;
char name[20];
struct listNode *p;
printf("Input name:");
scanf("%s",name);
p=head;
while(p!=NULL)
{if(strcmp(name,p->name)==0)
{printf("Num=%d\n",p->num);
printf("Name=%s\n",p->name);
printf("Sex=%c\n",p->sex);
printf("Age=%d\n",p->age);
for(i=0;i<5;i++)
printf("score[%d]=%d\n",i+1,p->score[i]);
}
p=p->next;
}
}
void FDnum()
{int i,snum;
struct listNode *p;
printf("Input num:");
scanf("&d",&snum);
p=head;
while(p!=NULL)
{ if(snum==p->num)
{ printf("Num=%d\n",p->num);
printf("Name=%s\n",p->name);
printf("Sex=%c\n",p->sex);
printf("Age=%d\n",p->age);
for(i=0;i<5;i++)
printf("score[%d]=%d\n",i+1,p->score[i]);
}
p=p->next;
}
}
void find_data()
{char ch;
while(1)
{
printf("\n1:Find by name\n");
printf("2:Find by num\n");
printf("3:Exit\n");
scanf("\n%c",&ch);
switch(ch)
{case '1': FDname();
break;
case '2': FDnum();
break;
case '3': return;
}
}
}
main()
{ head=NULL,tail=NULL;
input_data();
find_data();
}
编译後提示错误是这个
但是我都定义了的啊
--------------------Configuration: Text1 - Win32 Debug--------------------
Compiling...
Text1.c
c:\documents and settings\qqq\桌面\text1.c(26) : error C2018: unknown character '0xa3'
c:\documents and settings\qqq\桌面\text1.c(26) : error C2018: unknown character '0xbb'
c:\documents and settings\qqq\桌面\text1.c(27) : error C2146: syntax error : missing ';' before identifier 'scanf'
执行 cl.exe 时出错.
很着急啊