View Code of Problem 95

#include<stdio.h>
#include<string.h>
typedef struct student
{
	char name[20];
	char sex[10];
	int year;
	int month;
	int  day;
}student;

int main()
{
	student stu[30];
	char handle[20];	
	char name[20];
	char sex[10];
	int i=0,j,k;
	while(1)
	{		
		scanf("%s",handle);
		if(strcmp(handle,"add")==0)
		{
			scanf("%s %s %d %d %d",stu[i].name,stu[i].sex,&stu[i].year,&stu[i].month,&stu[i].day);
		//	printf("%s %s %d %d %d\n",stu[i].name,stu[i].sex,stu[i].year,stu[i].month,stu[i].day);	
			i++;
		}
		else if(strcmp(handle,"name")==0)
		{
			scanf("%s",name);
			for(j=0;j<i;j++)
			{
				if( strcmp(stu[j].name,name)==0 )
				printf("%s %s %d-%d-%d\n",stu[j].name,stu[j].sex,stu[j].year,stu[j].month,stu[j].day);	
			}
		}
		else if( strcmp(handle,"sex")==0 )
		{
			scanf("%s",sex);
			for(k=0;k<i;k++)
			{
				if( strcmp(stu[k].sex,sex)==0 )
				{
					printf("%s %s %d-%d-%d\n",stu[k].name,stu[k].sex,stu[k].year,stu[k].month,stu[k].day);
				}
			}
		}
		else if( strcmp(handle,"quit")==0 )
		{
			break;
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 95