新手上路,请多指教!
发表在C语言图书答疑
2011-10-27
是否精华
是
否
版块置顶:
是
否
<Visual C++ 从入门到精通>
第二章2.3.6结构体类型
TM\sl\2\4
实例中只调用了结构体中的年龄,如何调用结构体中的性别或是姓名,下面写了几种调用后的赋值方法,编译器都通过不了,请老师指教一下!
#include "stdafx.h"
const int MAX_CHAR = 128;
struct Student
{
char name[MAX_CHAR]; //姓名
char sex[MAX_CHAR]; //性别
unsigned int age; //年龄
char addr[MAX_CHAR]; //地址
} ;
void main()
{
Student stdnt; //定义一个结构体变量
stdnt.age = 10; //为结构体成员赋值
// stdnt.sex ={男};
// stdnt.sex = "男" ;
// stdnt.sex[1] = '男';
Student another; //再次定义一个结构体变量
another = stdnt; //直接为结构体变量赋值
printf("%d\n",another.age); //输出结构体成员信息
printf("%d\n",another.name);
}
第二章2.3.6结构体类型
TM\sl\2\4
实例中只调用了结构体中的年龄,如何调用结构体中的性别或是姓名,下面写了几种调用后的赋值方法,编译器都通过不了,请老师指教一下!
#include "stdafx.h"
const int MAX_CHAR = 128;
struct Student
{
char name[MAX_CHAR]; //姓名
char sex[MAX_CHAR]; //性别
unsigned int age; //年龄
char addr[MAX_CHAR]; //地址
} ;
void main()
{
Student stdnt; //定义一个结构体变量
stdnt.age = 10; //为结构体成员赋值
// stdnt.sex ={男};
// stdnt.sex = "男" ;
// stdnt.sex[1] = '男';
Student another; //再次定义一个结构体变量
another = stdnt; //直接为结构体变量赋值
printf("%d\n",another.age); //输出结构体成员信息
printf("%d\n",another.name);
}