冷夜雨落 2021-05-29 21:33 采纳率: 100%
浏览 41
已采纳

请各位大佬帮忙指点指点,感激不尽。

 和书上的代码一样,而且书上的代码还少了”#include <string.h>”我也加进去了

但为何运行结果却不能运行出年龄,生源地,录取成绩

我运行出的张三年龄为1703704   李四年龄为1703656

张三,李四生源地都为(null)

张三,李四录取成绩为 0

我用的是VC6.0

#include <stdio.h>
#include <string.h>

struct student  //声明 struct student 类型
{
	char id[9];     //学号
	char name[9];     //姓名
	int age;     //年龄
	char origin_place[10];     //生源地
	double score;     //录取成绩
};

int main()     //主函数
{
	struct student stul = {"TJUT0001","张三",18,"北京市",550.5};     //定义并初始化变量 stul
	struct student stu2;     //定义变量 stul2

	//为 stu2 的每个成员分别赋值
	strcpy (stu2.id, "TJUT0002");
	strcpy (stu2.name, "李四");
	strcpy (stu2.origin_place, "天津市");
	stu2.age = 20;
	stu2.score = 535.0;

	//按格式输出两个变量的每个成员值,使用\t 控制输出格式
	printf("学生基本信息汇总\n");
	printf("学号\t\t姓名\t\t年龄\t\t生源地\t\t录取成绩\n");
	printf("%s\t%s\t\t%d\t\t%s\t\t%.lf\n",
		stul.id,stul.name,stul.origin_place,stul.score);
	printf("%s\t%s\t\t%d\t\t%s\t\t%.lf\n",
		stu2.id,stu2.name,stu2.origin_place,stu2.score);
	return 0;
}
  • 写回答

4条回答 默认 最新

  • 关注

    你的输出语句,少了年龄那个字段啊,你用%d占了位,但是后面的语句没有这个值,导致了输出对不上。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示