View Code of Problem 95

#include<stdio.h>
#include<string.h>
struct people{
     char name[20];
	 char sex[10];
	 int birth[3];
};
int main(){
	char str[100];
	struct people man[30];
	int i=0,k;
	while(1){
		gets(str);
		if(strcmp(str,"add")==0)
		{scanf("%s%s%d%d%d",man[i].name,man[i].sex,&man[i].birth[0],&man[i].birth[1],&man[i].birth[2]);i++;}
		else if(strcmp(str,"name")==0)
			scanf("%s",man[i].name);
		else if(strcmp(str,"sex")==0)
			scanf("%s",man[i].sex);
		else  if (strcmp(str,"quit")==0)
			break;
	}
	    for(k=0;k<i;k++)
    {
    	if(strcmp(name,stu[k].name)==0)
    	{
    	printf("%s %s %d-%d-%d\n",stu[k].name,stu[k].sex,stu[k].year,stu[k].month,stu[k].day);
    	break;
        }
	}
	for(k=0;k<i;k++)
	{
	    if(strcmp(sex,stu[k].sex)==0)
    	     printf("%s %s %d-%d-%d\n",stu[k].name,stu[k].sex,stu[k].year,stu[k].month,stu[k].day);
	}
	return 0;
}
/*
Main.c: In function 'main':
Main.c:13:3: warning: 'gets' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
   gets(str);
   ^
Main.c:25:16: error: 'name' undeclared (first use in this function)
      if(strcmp(name,stu[k].name)==0)
                ^
Main.c:25:16: note: each undeclared identifier is reported only once for each function it appears in
Main.c:25:21: error: 'stu' undeclared (first use in this function)
      if(strcmp(name,stu[k].name)==0)
                     ^
Main.c:33:16: error: 'sex' undeclared (first use in this function)
      if(strcmp(sex,stu[k].sex)==0)
                ^
*/

Double click to view unformatted code.


Back to problem 95