View Code of Problem 95

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

Double click to view unformatted code.


Back to problem 95