View Code of Problem 95

#include<stdio.h>
#include <string.h>
#include <math.h>
struct student{
	char name[20];
	char sex[10];
	int year;
	int month;
	int day;
}stu[30];
int main(){
	char name[20];
	char sex[20];
	int i=0;
	int j;
	while(1){
		char s[100];
		scanf("%s",s);
		if(strcmp(s,"add")==0){
			scanf("%s %s %d %d %d",stu[i].name,stu[i].sex,&stu[i].year,&stu[i].month,&stu[i].day);
			i++;
		}
		else if(strcmp(s,"name")==0){
			gets(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(s,"sex")==0){
			gets(sex);
			for(j=0;j<i;j++){
				if(strcmp(sex,stu[j].sex)==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(s,"quit")==0){
			break;
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 95