#include<stdio.h> #include<string.h> struct student( char name[20]; char sex[10]; int year; int month; int day; ); int main() { int i=0,k; struct student[100]; char s[10]; while(scanf("%s",s)!=EOF) { if(strcmp(s,"add")==0) { scanf("%s%s%d%d%d",&student[i].name,&student[i].sex,&student[i].year,&student[i].month,&student[i].day) ; i++; } else if(strcmp(s,"name")==0) { char name[10]; scanf("%s",name); for(k=0;k<i;k++) { if(strcmp(student[k].name,name)==0) printf("%s %s %d-%d-%d\n",student[k].name,student[k].sex,student[k].year,student[k].month,student[k].day); } } else if(strcmp(s,"sex")==0) { char sex[10] ; scanf("%s",sex); for(k=0;k<i;k++) { if(strcmp(student[k].sex,sex)==0) printf("%s %s %d-%d-%d\n",student[k].name,student[k].sex,student[k].year,student[k].month,student[k].day); } } else if(strcmp(s,"quit")==0) break; } } /* Main.c:4:2: error: expected identifier or '(' before 'char' char name[20]; ^~~~ Main.c: In function 'main': Main.c:13:16: error: expected identifier or '(' before '[' token struct student[100]; ^ Main.c:19:24: error: 'student' undeclared (first use in this function) scanf("%s%s%d%d%d",&student[i].name,&student[i].sex,&student[i].year,&student[i].month,&student[i].day) ; ^~~~~~~ Main.c:19:24: note: each undeclared identifier is reported only once for each function it appears in */ |
Double click to view unformatted code.