求高手指导--将数据存放进文件中进行操作--出现错误
#include<math.h>#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define SIZE 100
typedef struct /*文件*/
{
short level; /*缓冲区“满”或“空”的程度*/
unsigned flags; /*文件状态标志*/
char fd; /*文件描述符*/
unsigned char hold; /*如无缓冲区不读取字符*/
short bsize; /*缓冲区的大小*/
unsigned char *buffer; /*数据缓冲区的位置*/
unsigned char *curp; /*指针,当前的指向*/
unsigned istemp; /*临时文件,指示器*/
short token; /*用于有效性检查*/
}File;
struct StudentInformation /*学生信息*/
{
char name[20]; /*学生姓名*/
int num; /*学生学号*/
char classes[15]; /*学生班级*/
int grade; /*学生成绩*/
}stud[SIZE];
int Loadgrades(File *fe) /*载入成绩*/
{
int i,k;
printf("\n ::----------------------------------------------------------------------::\n");
printf("\n ----------------------------------功能菜单模块--------------------------------");
printf("\n ------------- --------------");
printf("\n ------------- --------------");
printf("\n ------------- 载入成绩 --------------");
printf("\n ------------- --------------");
printf("\n ------------- --------------");
printf("\n ------------------------------------------------------------------------------");
printf("\n 请输入您要载入学生的个数:");
scanf("%d",&k);
printf("\n 姓名 学号 班级 成绩\n");
for(i=0;i<k;i++)
scanf("%s %d %s %d",stud[i].name,&stud[i].num,stud[i].classes,&stud[i].grade);
if((fe=fopen("stu_list","wb"))==NULL)
{
printf("对不起,不能打开文件!\n");
return 0;
}
for(i=0;i<k;i++)
{
if(fwrite(&stud[i],sizeof(struct StudentInformation),1,fe)!=1)
printf("很抱歉,文件写入出错!\n");
}
fclose(fe);
return 1;
}
int Operation(File *fe) /*系统综合操作*/
{
int j;
printf("请选择要执行的操作:");
scanf("%d",&j);
if(j>=0&&j<=9)
{
char ch;
switch(j)
{
case 1:system("cls");Loadgrades(fe);break;
case 2:system("cls");break;
case 3:system("cls");break;
case 4:system("cls");break;
case 5:system("cls");break;
case 6:system("cls");break;
case 7:system("cls");break;
case 8:system("cls");break;
case 9:system("cls");break;
case 0:printf("安全退出,谢谢参与!\n");exit(0);
}
printf("是否要继续进行以上操作(Y/N): ");
scanf("%s",&ch);
while(ch=='Y')
{
printf("请选择要执行的操作:");
scanf("%d",&j);
if(j>=0&&j<=9)
{
switch(j)
{
case 1:system("cls");Loadgrades(fe);break;
case 2:system("cls");break;
case 3:system("cls");break;
case 4:system("cls");break;
case 5:system("cls");break;
case 6:system("cls");break;
case 7:system("cls");break;
case 8:system("cls");break;
case 9:system("cls");break;
case 0:printf("安全退出,谢谢参与!\n");exit(0);
}
}
else
{
printf("您输入的不是有效的操作序号(0-9),请重新运行程序.\n谢谢参与!o(∩_∩)o...\n");
exit(0);
}
printf("是否要继续进行以上操作(Y/N): ");
scanf("%s",&ch);
}
if(ch=='N')
{
printf("操作结束,谢谢参与!o(∩_∩)o...\n");
exit(0);
}
if(ch!='Y'&&ch!='N')
printf("您输入的不是有效的操作符(Y/N),请重新运行程序.\n谢谢参与!o(∩_∩)o...\n");
}
else
printf("您输入的不是有效的操作序号(0-9),请重新运行程序.\n谢谢参与!o(∩_∩)o...\n");
return 1;
}
void main()
{
File *fp;
Operation(fp);
}
运行后出现以下错误:
:\Desktop\Sophomore courseware\数据结构\习题\查找与排序\查找与排序.cpp(44) : error C2440: '=' : cannot convert from 'struct _iobuf *' to 'File *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\Desktop\Sophomore courseware\数据结构\习题\查找与排序\查找与排序.cpp(51) : error C2664: 'fwrite' : cannot convert parameter 4 from 'File *' to 'struct _iobuf *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\Desktop\Sophomore courseware\数据结构\习题\查找与排序\查找与排序.cpp(54) : error C2664: 'fclose' : cannot convert parameter 1 from 'File *' to 'struct _iobuf *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
而且我把Flie全部改为FILE出现错误:
error C2371: 'FILE' : redefinition; different basic types
求大神指导,谢谢!!