View Code of Problem 95

#include<stdio.h>
#include<string.h>
typedef struct
{
  char name[20];
  char sex[10];
  char year[5];
  char month[5];
  char day[5];
}student;

int main()
{
  student s[20];
  int i;
  int count=0;
  char operation[20],come[20];
  while(scanf("%s",operation)!=NULL)
  {
    if(strcmp(operation,"quit")==0)
      break;
    if(strcmp(operation,"add")==0)
    {
      scanf("%s %s %s %s %s",&s[count].name,&s[count].sex,&s[count].year,&s[count].month,&s[count].day);
      count++;
    }
    else if(strcmp(operation,"name")==0)
    {
      scanf("%s",come);
      for(i=0;i<count;i++)
	  { 
		  if(strcmp(s[i].name,come)==0)
		  {
			  printf("%s %s %s-%s-%s\n",s[i].name,s[i].sex,s[i].year,s[i].month,s[i].day);
		      break;
		  }
	  }
    }
    else if(strcmp(operation,"sex")==0)
    {
      scanf("%s",come);
      for(i=0;i<count;i++)
        if(strcmp(s[i].sex,come)==0)
          printf("%s %s %s-%s-%s\n",s[i].name,s[i].sex,s[i].year,s[i].month,s[i].day);    
    }
  }
  return 0;
}

Double click to view unformatted code.


Back to problem 95