刚学习了结构体,想了一个程序编写后后发现出现问题了,程序的功能是:输入用户数量,名称,年龄,性别,出生日期,最后是输入用户信息
问题在输入后显示信息的不符合输入的
#define NUM 20
#include <conio.h>
struct date
{ int year;
int month;
int day;
};
struct info
{ char name[20],sex[10];
int age;
struct date bir;
};
struct info user[NUM];
int n;
void get_info(void)
{int i;
printf("Input the user amout:\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{ printf("Input the name of user No.%d:",i+1);
scanf("%s",user[i].name);
printf("Input the user sex:");
scanf("%s",user[i].sex);
printf("Input the user age:");
scanf("%d",&user[i].age);
printf("Input the birthday of user like this year-month-day :");
scanf("%d-%d-%d",&user[i].bir.year,&user[i].bir.month,&user[i].bir.day);
}
}
main()
{
void get_info(void);
void show_info(void);
get_info();/*输入信息*/
show_info();/*输出信息*/
getch();
}
void show_info(void)
{int i;
clrscr();
for(i=0;i<n;i++)
{int i;
printf("\n The No.%d user\n Name:%s\n sex:%s\n age:%d\n Birthday:%d-%d-%d\n",i+1,user[i].name,user[i].sex,user[i].age,user[i].bir.year,user[i].bir.month,user[i].bir.day);
printf("---------------------------------");
}
}