怎么给结构体中的二维字符型数组赋值?

如题所述

第1个回答  2012-05-20
1、直接初始化
2、利用成员运算符访问对其进行初始化
3、利用指针访问对其初始化追问

能简单的举个例子吗? 拜托啦

追答

1、直接初始化
struct student
{
char a[2][2]={{a,b},{c,d}};
};
2、利用成员运算符访问对其进行初始化
struct student
{
char a[2][2];
}stu;
stu.a[2][2]={{a,b},{c,d}};
3、利用指针访问对其初始化
struct student
{
char a[2][2];
}stu;
student *p=&stu;
p->a[2][2]={{a,b},{c,d}};或者(*p).a[2][2]={{a,b},{c,d}};
明白了吧。。。有什么不清楚的地方欢迎追问。。。

追问

struct Martrix
{
char data[5][4];
}mart;
void main()
{
mart mart1;
mart1.data[5][4]={{' ',' ',' ','*'},{' ',' ',' ','*'},{' ',' ',' ','*'},{' ',' ',' ','*'},{' ',' ',' ','*'}};
}
这个错在哪? 这是程序的一部分 谢谢啦

本回答被提问者采纳
相似回答