首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

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

2014-01-01 
结构体,错误。。。error C2275: 'student' : illegal use of this type as an exp#include STDIO.

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

#include <STDIO.H>
/*
 *
 *项目:有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 <STDIO.H>
/*
 *
 *    项目:有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 <stdio.h>
/*
 *  *
 *   *    项目:有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 <STDIO.H>
/*
 *
 *项目:有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

热点排行