请问大家哪里错了,一直运算不出来,求解答
提问:请问大家哪里错了,一直运算不出来,求解答
#include
网友回答:
这是修改好的程序:
#include
struct Student
{
int num;
char name[20];
char sex[10];
long phonenumber;
char youxiang[30];
};
int main()
{
struct Student *p;
struct Student stu[4]={{10001,"丽萍","男",86000001,"liping@126.com"},
{10002,"王芳","女",86000002,"wangf@163.com"},
{10003,"无病","女",86000003,"wubing@sina.com"},
{10004,"沥青","男",86000004,"liqing@yahoo.com"}};
printf("学号 t,名字 t,性别 t,电话号码 t,邮箱n");
for(p=stu;p { printf("%5d t,%s t,%s t,%9dt,%sn",p->num,p->name,p->sex,p->phonenumber,p->youxiang); } return 0; } 下面是结果图: 有两个错误:①手机号码太长,int型数据最大是32678,很明显你给的数据超出了范围,要么用long int,要用用数组 ②首先是p=stu,而不是p=&stu,因为stu已经是stu[]的地址了。然后你必须还要在p=stu之前给stu赋值,因为一旦p=stu,相当于p指向了stu[0]的首地址,那么再改吧stu[],是不会传递到p里面的。 还有问题吗,谢谢采纳,Thanks♪(・ω・)ノ