#include <stdio.h>
struct agent
{
char name[30];
int age;
} list[20];
main()
{
struct agent getData();
char ch;
int i = 0;
int j;
puts("1. Enter More");
puts("2. Display");
puts("3. Exit");
while ((ch = getchar()) < '3')
{
if (ch == '1')
{
list[i++] = getData();
}
else if (ch == '2')
{
for (j = 0; j < i; j++)
{
puts(list[j].name);
printf("%d\n", list[j].age);
}
}
puts("1. Enter More");
puts("2. Display");
puts("3. Exit");
}
}
struct agent getData(
{
struct agent tmp;
puts("Enter name");
scanf(" %s",tmp.name);
puts("Enter age");
scanf("%d",&tmp.age);
return tmp;
}
输出:
1. Enter More
2. Display
3. Exit
1
Enter name
ace
Enter age
23
1. Enter More
2. Display
3. Exit
1. Enter More
2. Display
3. Exit
3
为什么这些语句“1. Enter More 2. Display 3. Exit”会重复?