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

u013096814 2013-12-13 12:11:41
#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
...全文
188 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
derekrose 2013-12-13
  • 打赏
  • 举报
回复
楼主先去看看声明和定义的区别吧
zhouda829829 2013-12-13
  • 打赏
  • 举报
回复
#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才是字符串。
    }
}
d4shman 2013-12-13
  • 打赏
  • 举报
回复
引用 4 楼 turingo 的回复:
问题很多,都帮你改好了:

#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;
}
[quote=引用 楼主 u013096814 的回复:]
#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
[/quote] good
JiMoKuangXiangQu 2013-12-13
  • 打赏
  • 举报
回复
图灵狗 2013-12-13
  • 打赏
  • 举报
回复
问题很多,都帮你改好了:

#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;
}
引用 楼主 u013096814 的回复:
#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
N_Sev7 2013-12-13
  • 打赏
  • 举报
回复

struct student
{
    char name;
    int number;
    int score1;
    int score2;
    int score3;
 
};//////这样是定义中自定义类型  就像int等数据类型 只不过这是自定义的
///你觉得int[i]这样能能用吗?肯定不能啊  同样
///你得定义变量  
student s[10];
///这样才能用
仔细想想自定义数据类型是什么意思

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧