学生互换信息的结构体,在19行还有s2和s3两个变量没显示出来

 

s1和s2交换的代码如下:如有帮助,请采纳一下,谢谢。

#include <stdio.h>
#include <string.h>
struct data
{
	int year;
	int month;
	int day;
};
struct stu
{
	int num;
	char name[20];
	char sex;
	struct data birth;
	float score;
};
int main()
{
	struct stu s1 = {10010,"zhangsan",'m',2000,5,4,84.5};
	struct stu s2 = {};
	char tmp[20] = {0};
	int t;
	char sex;
	float sc;
	printf("请输入学生2的学号:");
	scanf("%d",&s2.num);
	printf("请输入写生2的姓名:");
	scanf("%s",s2.name);
	printf("请输入学生2的性别:");
	scanf(" %c",&s2.sex);
	printf("请输入学生2的生日:");
	scanf("%d %d %d",&s2.birth.year,&s2.birth.month,&s2.birth.day);
	printf("请输入学生2的成绩:");
	scanf("%f",&s2.score);
	//交换
	//num
	t = s1.num;
	s1.num = s2.num;
	s2.num = t;
	//name
	strcpy(tmp,s1.name);
	memset(s1.name,0,20);
	strcpy(s1.name,s2.name);
	memset(s2.name,0,20);
	strcpy(s2.name,tmp);
	//sex
	sex = s1.sex;
	s1.sex = s2.sex;
	s2.sex = sex;
	//birth
	t = s1.birth.year;
	s1.birth.year = s2.birth.year;
	s2.birth.year = t;
	t = s1.birth.month;
	s1.birth.month = s2.birth.month;
	s2.birth.month = t;
	t = s1.birth.day;
	s1.birth.day = s2.birth.day;
	s2.birth.day = t;
	//score
	sc = s1.score;
	s1.score = s2.score;
	s2.score = sc;
	//输出s1和s2
	printf("学号:%d\n",s1.num);
	printf("姓名:%s\n",s1.name);
	printf("性别:%c\n",s1.sex);
	printf("出生日期:%d年%d月%d日\n",s1.birth.year,s1.birth.month,s1.birth.day);
	printf("成绩:%g\n",s1.score);
	printf("学号:%d\n",s2.num);
	printf("姓名:%s\n",s2.name);
	printf("性别:%c\n",s2.sex);
	printf("出生日期:%d年%d月%d日\n",s2.birth.year,s2.birth.month,s2.birth.day);
	printf("成绩:%g\n",s2.score);
}