View Code of Problem 95

#include <stdio.h>
#include <string.h>
typedef struct {
  char name[20];
  char sex[8];
  int year;
  int month;
  int day;
  
}student;
int main(){
  student s[30];
  char a[10];
  int i=0,j;
  char b[20];
  while(1){
    scanf("%s",a);
    if(strcmp(a,"add")==0){
      scanf("%s %s %d %d %d",&s[i++].name,&s[i++].sex,&s[i++].year,&s[i++].month,&s[i++].day);
    }
    else if(strcmp(a,"name")==0){
      scanf("%s",b);
      for(j=0;j<=i;j++){
        if(strcmp(s[j].name,b)==0)
          printf("%s %s %d-%d-%d\n",s[j].name,s[j].sex,s[j].year,s[j].month,s[j].day);
      }
    }
    else if(strcmp(a,"sex")==0){
		scanf("%s",b);
      for(j=0;j<=i;j++){
        if(strcmp(s[j].sex,b)==0)
          printf("%s %s %d-%d-%d\n",s[j].name,s[j].sex,s[j].year,s[j].month,s[j].day);
    }
      
  }
	else if(strcmp(a,"quit")==0)
        break;
  }
  
  
  return 0;
}

Double click to view unformatted code.


Back to problem 95