c语言问题,求高手。我用的是VC6.0,下面的代码怎么不能运行。
#include"common1.h"voidmain(){FILE*fp=NULL;structstudentTmpS;charDataFile[40]="";intc...
#include "common1.h"
void main()
{
FILE *fp = NULL;
struct student TmpS;
char DataFile[40] = "";
int count = 1; /*Circular variable is to control maximum of input data.*/
/*====input number ,name and grade of english.number is 0 means input is end=====*/
printf("\nplease input the file name to store data,end with enter.");
printf("\n(Notice:Name of file can't exceed 8 characters,\nsuffix can't exceed 3 characters,\npart of exceed will be discarded.)\n");
scanf("%s",DataFile);
while(DataFile[0] == ('\0'))
{
printf("\nplease input new file name to store data,end with enter.");
printf("\n(Notice:Name of file can't exceed 8 characters,\nsuffix can't exceed 3 characters,\npart of exceed will be discarded.)\n");
scanf("%s",DataFile);
}
fp = fopen(DataFile,"wb+");
if (fp == NULL)
{
printf("\n Open file %s fail!End with any key.\n",DataFile);
exit(1);
}
printf("Please input student infomation.\n0 means end.\n");
printf("(Notice:Number is not exceed 9 figures;Name is not exceed 20 characters;Range of grade:0~100)\n");
while(count <= SIZE) /* It's to control recorders less then maximum of stated input data. */
{
printf("Student number:");
scanf("%ld",&TmpS.number);
if (TmpS.number == 0 )
break;
printf("Student name:");
scanf("%s",TmpS.name);
printf("englishscore:");
scanf("%d",&TmpS.score);
printf("\n");
if(fwrite(&TmpS,sizeof(LENGTH),1,fp)!=1)
{
printf("\nwrite file %s fail!End with any key\n",DataFile);
getch();
exit(1);
}
count++;
}
if (count>SIZE)
printf("\nsorry,number of data can not exceed %d\n",SIZE);
fclose(fp);
/*====Showing content of file on screen.====*/
printf("The data has stored successfully in file %s.\n",DataFile);
printf("Content as follow:\n");
fp=fopen(DataFile,"rb");
if (fp == NULL)
{
printf("\nOpen file%sfail!End with any key \n",DataFile);
exit(1);
}
printf("\n Number\tName\tEnglishscore\n");
while(fread(&TmpS,sizeof(LENGTH),1,fp) != (int)NULL)
{
printf("\n%9ld\t%s\t%8d\n",TmpS.number,TmpS.name,TmpS.score);
}
fclose(fp);
getch(); 展开
void main()
{
FILE *fp = NULL;
struct student TmpS;
char DataFile[40] = "";
int count = 1; /*Circular variable is to control maximum of input data.*/
/*====input number ,name and grade of english.number is 0 means input is end=====*/
printf("\nplease input the file name to store data,end with enter.");
printf("\n(Notice:Name of file can't exceed 8 characters,\nsuffix can't exceed 3 characters,\npart of exceed will be discarded.)\n");
scanf("%s",DataFile);
while(DataFile[0] == ('\0'))
{
printf("\nplease input new file name to store data,end with enter.");
printf("\n(Notice:Name of file can't exceed 8 characters,\nsuffix can't exceed 3 characters,\npart of exceed will be discarded.)\n");
scanf("%s",DataFile);
}
fp = fopen(DataFile,"wb+");
if (fp == NULL)
{
printf("\n Open file %s fail!End with any key.\n",DataFile);
exit(1);
}
printf("Please input student infomation.\n0 means end.\n");
printf("(Notice:Number is not exceed 9 figures;Name is not exceed 20 characters;Range of grade:0~100)\n");
while(count <= SIZE) /* It's to control recorders less then maximum of stated input data. */
{
printf("Student number:");
scanf("%ld",&TmpS.number);
if (TmpS.number == 0 )
break;
printf("Student name:");
scanf("%s",TmpS.name);
printf("englishscore:");
scanf("%d",&TmpS.score);
printf("\n");
if(fwrite(&TmpS,sizeof(LENGTH),1,fp)!=1)
{
printf("\nwrite file %s fail!End with any key\n",DataFile);
getch();
exit(1);
}
count++;
}
if (count>SIZE)
printf("\nsorry,number of data can not exceed %d\n",SIZE);
fclose(fp);
/*====Showing content of file on screen.====*/
printf("The data has stored successfully in file %s.\n",DataFile);
printf("Content as follow:\n");
fp=fopen(DataFile,"rb");
if (fp == NULL)
{
printf("\nOpen file%sfail!End with any key \n",DataFile);
exit(1);
}
printf("\n Number\tName\tEnglishscore\n");
while(fread(&TmpS,sizeof(LENGTH),1,fp) != (int)NULL)
{
printf("\n%9ld\t%s\t%8d\n",TmpS.number,TmpS.name,TmpS.score);
}
fclose(fp);
getch(); 展开
4个回答
展开全部
斌不是想不帮你,没拿那能力
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
commom1.h没给出来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
错误提示呢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询