猿问

这个程序到底怎么了 运行不了 能帮帮忙吗?

#include<stdio.h>

#include<string.h>


int main()

{

struct student

{

long nu;

char name[10];

int age;

};


struct student stu_i;

struct student*p;

p=&stu_i;

stu_1.nu =201601;

stu_1.age =12;

strcpy(stu_1.name ,"xiong");


stu_2.nu =201602;

stu_2.age =15;

strcpy(stu_2.name ,"xiong");


stu_3.nu =201603;

stu_3.age =20;

strcpy(stu_3.name ,"tong");


stu_4.nu =201604;

stu_4.age =21;

strcpy(stu_4.name ,"zeng");


stu_5.nu =201605;

stu_5.age =19;

strcpy(stu_5.name ,"mao");

int i;

i=0;

for(i=0;i<5;i++)

{

printf("number is :%d\nname is:%s\nage is:%d\n",(*p).nu,(*p).name,(*p).age);

}

return 0;

}


熊熊熊熊
浏览 1754回答 3
3回答

leic

定义了stu_i而没有定义stu_1, stu_2, stu_3, stu_4, stu_5C还没有这么智能,可以把i默认为各int类型,建议楼主有空好好看看C的基本语法,另外在问问题的时候能一起把错误提示贴出来对于获取答案也会更有益处

乱舞的旋律

struct student stu_i; 改成struct student ,stu_2,stu_3,stu_4,stu_5;还有  结构体一般写在 main函数外边的 写成全局,你这样子编程不是很规范

guozhchun

stu_1, stu_2, stu_3, stu_4, stu_5这些变量都没有声明,故编译出错
随时随地看视频慕课网APP
我要回答