打印的空格你自己调整下。
程序代码:
#include<stdio.h>
#include<string.h>
struct data
{
int year;
int month;
int day;
};
struct techer//结构体变量
{
char name[20];//姓名
char sex[4];//性别
struct data birthday;//出生日期
char addr[100];
int tel;
float revenue;
}techers[100];
int main()
{
char in;
int count = 0,i = 0;
while (1)
{
printf("请输入教师信息,确认按y,取消按n:");
scanf(" %c",&in);
if ((in == 'y') || (in == 'Y'))
{
printf("请输入教师姓名:");
scanf(" %s", techers[count].name);
printf("请输入教师性别:");
scanf(" %s", techers[count].sex);
printf("请输入教师出生日期(格式:xxxx.xx.xx):");
scanf("%d.%d.%d", &techers[count].birthday.year, &techers[count].birthday.month, &techers[count].birthday.day);
printf("请输入教师住址:");
scanf(" %s", techers[count].addr);
printf("请输入教师电话:");
scanf("%d", &techers[count].tel);
printf("请输入教师收入:");
scanf("%f", &techers[count].revenue);
count++;
}
else
{
break;
}
}
printf(" 姓名\t性别\t出生日期\t住址\t\t电话\t 月收入\n");
for (i = 0; i < count; i++)
{
printf("%d. %s\t%s\t%d年%d月%d日\t%s\t%d\t %.2f\n"
,i+1 ,techers[i].name, techers[i].sex
, techers[i].birthday.year, techers[i].birthday.month, techers[i].birthday.day
, techers[i].addr, techers[i].tel, techers[i].revenue);
}
}