View Code of Problem 95

#include <stdio.h>
#include <string.h>
typedef struct{
	char name[20];
	char sex[6];
	int year;
	int month;
	int day;
}people;
int main(){
	void name(people a[],int count,char b[]);
	void sex(people a[],int count,char b[]);
	people a[30];
	int count=0,i;     //计数的 表示现在有几个人在记录里了 
	char c[5];
	while(scanf("%s",c)!=EOF&&strcmp(c,"quit")!=0){
		if(strcmp(c,"add")==0){
			scanf("%s %s %d %d %d",a[count].name,a[count].sex,&a[count].year,&a[count].month,&a[count].day);
			count++;
		}
		if(strcmp(c,"name")==0){
			char b[20];
			scanf("%s",b);
			name(a,count,b);
		}
		if(strcmp(c,"sex")==0){
			char b[6];
			scanf("%s",b);
			sex(a,count,b);
		}
	}
}
void name(people a[],int count,char b[]){
	int i;
	for(i=0;i<count;i++){
		if(strcmp(a[i].name,b)==0){
			printf("%s %s %d-%d-%d\n",a[i].name,a[i].sex,a[i].year,a[i].month,a[i].day);
		}
	}
}
void sex(people a[],int count,char b[]){
	int i;
	for(i=0;i<count;i++){
		if(strcmp(a[i].sex,b)==0){
			printf("%s %s %d-%d-%d\n",a[i].name,a[i].sex,a[i].year,a[i].month,a[i].day);
		}
	}
}

Double click to view unformatted code.


Back to problem 95