View Code of Problem 95

#include<stdio.h>
typedef struct 
{
	char name[20];
	char sex[10];
	int year;
	int month;
	int day;
}mess;
main() {
	mess mes[10000];
	char arr1[20];
	char str[100];
	int i = 0;
	while (scanf("%s", &str) != EOF)
	{
		if (strcmp(str, "add") == 0)
		{
			scanf("%s%s%d%d%d", &mes[i].name, &mes[i].sex, &mes[i].year, &mes[i].month, &mes[i].day);
			i++;
		}

		else if (strcmp(str, "name") == 0)
		{
			scanf("%s", arr1);
			for (int q = 0; q < i; q++)
			{
				if (strcmp(arr1, mes[q].name) == 0)
				{
					printf("%s %s %d-%d-%d\n", mes[q].name, mes[q].sex, mes[q].year, mes[q].month, mes[q].day);
				}
			}
		}
		else if (strcmp(str, "sex") == 0)
		{
			scanf("%s", arr1);
			for (int j = 0; j < i; j++)
			{
				if (strcmp(mes[j].sex, arr1) == 0)
					printf("%s %s %d-%d-%d\n", mes[j].name, mes[j].sex, mes[j].year, mes[j].month, mes[j].day);
			}
		}
		else if (strcmp(str, "quit") == 0)
		{
			break;
		}
	}
}
	

Double click to view unformatted code.


Back to problem 95