关于C语言中的typedef struct 的用法问题,编译器是VC 6.0

如题所述

有三个问题:
一、语句不要写在结构体的定义及main函数之间,请写到main里面
二、如果用字符数组存储字符串,则赋值时不能直接用字符串赋值,要改用strcpy进行,为简化操作,请把字符数组,改成字符指针
三、输出字符串要用%s,不是%c
修改后的代码如下:
#include
typedef struct student
{
int age;
float score;
char * name;
}stu;
int main(void)
{
stu stu1;
stu1.age=27;
stu1.score=79.00;
stu1.name="zheng shuai";
printf("name:%s,age:%d,ang score:%f",stu1.name,stu1.age,stu1.score);
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2020-03-25
语句要写到语句块里面,语句块之外,可以
定义变量,不可以
写语句的。
#include
typedef
struct
student
{
int
age;
float
score;
char
name[20];
}stu;
void
main()
{
stu
stu1;
stu1.age=27;
stu1.score=79.00;
stu1.name="zheng
shuai";
printf("name:%c,age:%d,ang
score:%f",stu1.name,stu1.age,stu1.score);
}
第2个回答  2019-02-11
你把代码写到函数外面是什么意思?
#include
typedef
struct
student
{
int
age;
float
score;
char
name[20];
}stu;
void
main()
{
stu
stu1;
stu1.age=27;
stu1.score=79.00;
stu1.name="zheng
shuai";
printf("name:%c,age:%d,ang
score:%f",stu1.name,stu1.age,stu1.score);
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网