View Code of Problem 95

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

Double click to view unformatted code.


Back to problem 95