View Code of Problem 95

#include<stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#define Max 100
struct stu{
	char name[20];
	char sex[10];
	int y;
	int m;
	int d;
};
int main()
{
	int i=0,j;
	char a[Max],name[Max],sex[Max];
	struct stu s[30];
	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(s[j].name,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(s[j].sex,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