回复 7楼 惧惧
如果想多次输入,试试下面这个,不输入任何数按两次回车退出
#include <stdio.h>
#include <string.h>
main()
{
struct stu
{
char name[20];
int number;
int grade;
char mark[10];
}student[5]={
{"wang",23,78,"great"},
{"li",12,56,"bad"},
{"liu",33,6,"good"},
{"xu",26,89,"great"},
{"miao",32,76,"great"}};
int i,n;
char name1[20];
while(gets(name1)&&name1[0]!='\0')
{
n=5;
for(i=0;i<5;i++)
{
if(!strcmp(name1,student[i].name))
{
n=i;
break;
}
}
if(n!=5)
printf("%s\'s mark is %s\n",student[n].name,student[n].mark);
else
printf("%s does not exist.\n",name1);
}
getchar();
}