View Code of Problem 95

#include <stdio.h>
#include <string.h>

typedef struct{
	char name[20];
	char sex[10];
	int year;
	int month;
	int day;
}People;

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

Double click to view unformatted code.


Back to problem 95