c语言error c2275,结构体,异常。error C2275: 'student' : illegal use of this type as an exp

结构体,错误。。。error C2275: 'student' : illegal use of this type as an exp

#include 

/*

*

*项目:有5个学生,每个学生的数据包括学号、姓名、三门课的成……

*

*日期:2013-12-12

*

*

*

*/

struct student

{

char name;

int number;

int score1;

int score2;

int score3;

};

void main()

{for (int i=1;i<6;i++)

{

printf("请输入第%个学生的姓名",i);

scanf("%c",&student[i].name);

}

}

结构体,错误。。。error C2275: 'student' : illegal use of this type as an exp

分享到:

更多

------解决方案--------------------

#include 

/*

*

*    项目:有5个学生,每个学生的数据包括学号、姓名、三门课的成……

*

*    日期:2013-12-12

*

*

*

*/

struct student{

char name;

int number;

int score1;

int score2;

int score3;

}stu[5];//上面只是定义了这个一个结构体,下面这里才是定义五个学生;

void main(void){

int i;//最好这样定义

for(i=0;i<5;i++){//i要从0开始,因为你定义的5个学生从stu[0]开始;

printf("请输入第%d个学生的姓名",i+1);//printf()函数输出i,前面对应的是

scanf("%s",&stu[i].name);//%c是一个字符,%s才是字符串。

}

}

------解决方案--------------------

楼主先去看看声明和定义的区别吧

------解决方案--------------------

struct student

{

char name;

int number;

int score1;

int score2;

int score3;

};//这样是定义中自定义类型  就像int等数据类型 只不过这是自定义的

///你觉得int[i]这样能能用吗?肯定不能啊  同样

///你得定义变量

student s[10];

///这样才能用

仔细想想自定义数据类型是什么意思

------解决方案--------------------

问题很多,都帮你改好了:

#include 

/*

*  *

*   *    项目:有5个学生,每个学生的数据包括学号、姓名、三门课的成……

*    *

*     *    日期:2013-12-12

*      *

*       *

*        *

*         */

struct student

{

char name[20];

int number;

int score1;

int score2;

int score3;

};

int main()

{

struct student stus[6];

int i;

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

{

printf("请输入第%d个学生的姓名",i);

scanf("%s",stus[i].name);

}

return 0;

}

引用:#include 

/*

*

*项目:有5个学生,每个学生的数据包括学号、姓名、三门课的成……

*

*日期:2013-12-12

*

*

*

*/

struct student

{

char name;

int number;

int score1;

int score2;

int score3;

};

void main()

{for (int i=1;i<6;i++)

{

printf("请输入第%个学生的姓名",i);

scanf("%c",&student[i].name);

}

}

结构体,错误。。。error C2275: 'student' : illegal use of this type as an exp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值