和书上的代码一样,而且书上的代码还少了”#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;
}