View Code of Problem 95

#include<stdio.h>
#include<string.h>
typedef struct student{
   char name[20];
   char sex[20];
   int y,m,d;
}stu;
int main()
{
	stu s[30];
	int i=0,j;
	 char name[20];
   char sex[20];
	char a[20];
	char si[20];
	while(1)
	{
		scanf("%s",&a);
		if(strcmp(a,"add")==0)
		{
			scanf("%s %s %d %d %d",&s[i].name,&s[i].sex,&s[i].y,&s[i].m,&s[i].d);
		      i++;
		}
		else if(strcmp(a,"name")==0)
		{
			scanf("%s",&name);
		
		}
		else if(strcmp(a,"sex")==0)
		{
			scanf("%s",&sex);
		
		}
		else if(strcmp(a,"quit")==0)
	        	break;
		
	}
		for(j=0;j<i;j++)
			{
				if(strcmp(name,s[j].name)==0)
				printf("%s %s %d-%d-%d\n",s[j].name,s[j].sex,s[j].y,s[j].m,s[j].d);
			}
		for(j=0;j<i;j++)
			{
				if(strcmp(sex,s[j].sex)==0)
				printf("%s %s %d-%d-%d\n",s[j].name,s[j].sex,s[j].y,s[j].m,s[j].d);
			}
	return 0;
	
}

Double click to view unformatted code.


Back to problem 95