为什么不运行呢 调试也不行
#include"stdio.h"
#include"string.h"
#define NULL 0
struct student
{
long num,tel;
char name[2][2],sex[1],address[5][2];
struct student *next;
};
int main(int argc, char* argv[])
{
char name1[2][2]={'张','三'},name2[2][2]={'李','四'},name3[2][2]={'王','五'};
char address1[5][2]={'A','_','1','0','1'},address2[5][2]={'b','_','1','0','1'},address3[5][2]={'a','_','1','0','2'};
char sex1[1]={'男'},sex2[1]={'女'},sex3[1]={'男'};
struct student a,b,c,*head,*p;
a.num=10101;
a.name[2][2]=name1[2][2];
a.sex[1]=sex1[1];
a.tel=11111111;
a.address[5][2]=address1[5][2];
b.num=10103;
b.name[2][2]=name2[2][2];
b.sex[1]=sex2[1];
b.tel=22222222;
b.address[5][2]=address2[5][2];
c.num=10105;
c.name[2][2]=name3[2][2];
c.sex[1]=sex3[1];
c.address[5][2]=address3[5][2];
c.tel=33333333;
head=&a;
a.next=&b;
b.next=&c;
c.next=NULL;
p=head;
do
{
printf("%ld %c %c %c %ld\n",p->num,p->name,p->sex,p->address,p->tel);
p=p->next;
}while(p!=NULL);
return 0;
}
----------------解决方案--------------------------------------------------------
代你找到一个大错:
'张'是错的,因为1个汉字编码占2个byte
所以这样一来,肯定玩不起来。
其他汉字也是如此啦。
----------------解决方案--------------------------------------------------------
我想不通你为什么要定义char name[2][2],,其实这种变量的申明一般就用一维数组就行了,这样操作也简单~!还有就是上楼说的数组越界的问题~!你把简单的问题复杂化了!~
----------------解决方案--------------------------------------------------------