标题:有没有懂得,问一下这个结构体的问题怎么解决呀
取消只看楼主
wyh416
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2020-10-9
结帖率:33.33%
 问题点数:0 回复次数:4 
有没有懂得,问一下这个结构体的问题怎么解决呀
/*1.某学校要开发一个新生注册系统,新生的信息包括:序号、姓
名、性别、高考准考证号,高考总成绩,现输入录取学生的人数
(小于 5 人),请输入学生的信息,将信息写入文件 exm.dat 中,
并将信息读取出来。
提示:
1) 定义一个结构体
2) 动态内存分配
3) 输入学生信息
4) 选用 fwrite() fread() */
#include<stdio.h>
#include<stdlib.h>
struct stu_info
{  char xm[10];
   char xb[10];
   char zh[10];
   float zcj[10];
};
typedef struct stu_info STU;
 main()
{int n,i;
 STU *p,*q;
 printf("请输入人数",n);
     scanf("%d",&n);
     p=(*STU)malloc(n*sizeof(STU));
     q=(*STU)malloc(n*sizeof(STU));
     if(p==NULL)
     {
         printf("动态内从分配失败");
         exit(0);
     }
     for(i=0;i<n;i++)
     {
         fflush(stdin);
         printf("请输入该学生的姓名",i);
             gets((p+i)->xm);
         printf("请输入该学生的性别",i);
             gets((p+i)->xb);
         fflush(stdin);
         printf("请输入该学生的准考证号",i);
             gets((p+i)->zh);
         printf("请输入高考总成绩",i);
             scanf("%f",&(p+i)->zcj);                  
         fflush(stdin);
     }


     





                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
return 0
};
  

--------------------Configuration: c_1 - Win32 Debug--------------------
Compiling...
c_1.cpp
E:\计算机程序设计\练习\c_1.cpp(24) : error C2275: 'STU' : illegal use of this type as an expression
        E:\计算机程序设计\练习\c_1.cpp(18) : see declaration of 'STU'
E:\计算机程序设计\练习\c_1.cpp(24) : error C2146: syntax error : missing ';' before identifier 'malloc'
E:\计算机程序设计\练习\c_1.cpp(25) : error C2275: 'STU' : illegal use of this type as an expression
        E:\计算机程序设计\练习\c_1.cpp(18) : see declaration of 'STU'
E:\计算机程序设计\练习\c_1.cpp(25) : error C2146: syntax error : missing ';' before identifier 'malloc'
E:\计算机程序设计\练习\c_1.cpp(63) : error C2143: syntax error : missing ';' before '}'
执行 cl.exe 时出错.

c_1.exe - 1 error(s), 0 warning(s)
 小白上路,这个结构体的问题,有没有会的,指点一下
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
搜索更多相关主题的帖子: STU 输入 cpp 程序设计 计算机 
2021-04-20 14:30
wyh416
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2020-10-9
得分:0 
回复 2楼 rjsp
不要强制类型转换吗!
2021-04-20 15:02
wyh416
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2020-10-9
得分:0 
回复 2楼 rjsp
--------------------Configuration: c_1 - Win32 Debug--------------------
Compiling...
c_1.cpp
E:\计算机程序设计\练习\c_1.cpp(24) : error C2440: '=' : cannot convert from 'void *' to 'struct stu_info *'
        Conversion from 'void*' to pointer to non-'void' requires an explicit cast
E:\计算机程序设计\练习\c_1.cpp(25) : error C2440: '=' : cannot convert from 'void *' to 'struct stu_info *'
        Conversion from 'void*' to pointer to non-'void' requires an explicit cast
E:\计算机程序设计\练习\c_1.cpp(56) : error C2143: syntax error : missing ';' before '}'
执行 cl.exe 时出错.

c_1.exe - 1 error(s), 0 warning(s)
  第三种就有这样子的错误了
2021-04-20 15:06
wyh416
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2020-10-9
得分:0 
回复 5楼 rjsp
哦哦,谢谢!
2021-04-20 15:12
wyh416
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2020-10-9
得分:0 
回复 7楼 rjsp
谢谢!
2021-04-20 15:21



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-505514-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028402 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved