View Code of Problem 95

#include <stdio.h>
#include <string.h>
#include <math.h>
struct people {
	char name[20];
	char sex[10];
	int year;
	int month;
	int day;
};
int main()
{
	int i, j, k, l;
	char order[5];
	struct people p[100];
	l = 0;
	while (scanf("%s",order)!=EOF)
	{
		k = 0;
		if (strcmp(order, "add") == 0)
		{
			int z = l;
			l++;
			scanf("%s%s%d%d%d", p[z].name, p[z].sex, &p[z].year, &p[z].month, &p[z].day);
		}
		else if (strcmp(order, "name") == 0)
		{
			int nam[20];
			scanf("%s", nam);
			for (i = 0; i < l; i++)
			{
				if (strcmp(nam, p[i].name) == 0)
					printf("%s %s %d-%d-%d\n", p[i].name, p[i].sex, p[i].year, p[i].month, p[i].day);
				else
					continue;
			}
		}
		else if (strcmp(order, "sex") == 0)
		{
			char sex[10];
			scanf("%s", sex);
			for (i = 0; i < l; i++)
			{
				if (strcmp(sex, p[i].sex) == 0)
					printf("%s %s %d-%d-%d\n", p[i].name, p[i].sex, p[i].year, p[i].month, p[i].day);
				else
					continue;
			}

		}
		else if (strcmp(order, "quit") == 0)
			break;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 95