#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ struct message{ char name[100]; char sex[100]; int year; int month; int day; }mes[1000]; int main() { char a[1000],b[1000],c[1000]; int i=0,j; while(scanf("%s",&a)!=EOF){ if(strcmp(a,"quit")==0){ break; } if(strcmp(a,"add")==0){ scanf("%s %s %d %d %d",&mes[i].name,&mes[i].sex,&mes[i].year,&mes[i].month,&mes[i].day); i++; } if(strcmp(a,"name")==0){ scanf("%s",&b); for(j=0;j<i;j++){ if(strcmp(b,mes[j].name)==0){ printf("%s %s %d-%d-%d\n",mes[j].name,mes[j].sex,mes[j].year,mes[j].month,mes[j].day); } } } if(strcmp(a,"sex")==0){ scanf("%s",&c); for(j=0;j<i;j++){ if(strcmp(c,mes[j].sex)==0){ printf("%s %s %d-%d-%d\n",mes[j].name,mes[j].sex,mes[j].year,mes[j].month,mes[j].day); } } } } } |
Double click to view unformatted code.