C语言子函数文件写不进去
voidwrite()/*录入班次信息*/{inti;intt=1;FILE*fp;structticketcar[100];if((fp=fopen("informat...
void write() /*录入班次信息*/
{
int i;
int t=1;
FILE *fp;
struct ticket car[100];
if((fp=fopen("information.txt","w"))==NULL) /*将班次信息写入文件information.txt中*/
{
printf("File open error!\n");
exit(0);
}
for(i=0;t=1;i++)
{
printf("请输入班次次数");
scanf("%d",&car[i].Number);
fprintf(fp,"%d",car[i].Number);
printf("请输入发车时间(先小时,后分钟)");
scanf("%d",&car[i].Setout.hour);
fprintf(fp,"%d",car[i].Setout.hour);
scanf("%d",&car[i].Setout.minutes);
fprintf(fp,"%d",car[i].Setout.minutes);
printf("请输入起点站");
scanf("%s",&car[i].Qidian);
fprintf(fp,"%s",car[i].Qidian);
printf("请输入终点站");
scanf("%s",&car[i].Zhongdian);
fprintf(fp,"%s",car[i].Zhongdian);
printf("请输入行车时间(hour)");
scanf("%f",&car[i].Lasttime);
fprintf(fp,"%f",car[i].Lasttime);
printf("请输入额定载量");
scanf("%d",&car[i].Fixnumber);
fprintf(fp,"%d",car[i].Fixnumber);
printf("请输入已订票人数");
scanf("%d",&car[i].Fixednumber);
fprintf(fp,"%d",car[i].Fixednumber);
printf("是否继续录入班次信息,“是”请输入1,“否”请按任意键退出");
scanf("%d",&t);
if(t!=1)
welcome();
}
if(fclose(fp))
{
printf("Can not close the file!\n");
exit(0);
} /*关闭文件*/ 展开
{
int i;
int t=1;
FILE *fp;
struct ticket car[100];
if((fp=fopen("information.txt","w"))==NULL) /*将班次信息写入文件information.txt中*/
{
printf("File open error!\n");
exit(0);
}
for(i=0;t=1;i++)
{
printf("请输入班次次数");
scanf("%d",&car[i].Number);
fprintf(fp,"%d",car[i].Number);
printf("请输入发车时间(先小时,后分钟)");
scanf("%d",&car[i].Setout.hour);
fprintf(fp,"%d",car[i].Setout.hour);
scanf("%d",&car[i].Setout.minutes);
fprintf(fp,"%d",car[i].Setout.minutes);
printf("请输入起点站");
scanf("%s",&car[i].Qidian);
fprintf(fp,"%s",car[i].Qidian);
printf("请输入终点站");
scanf("%s",&car[i].Zhongdian);
fprintf(fp,"%s",car[i].Zhongdian);
printf("请输入行车时间(hour)");
scanf("%f",&car[i].Lasttime);
fprintf(fp,"%f",car[i].Lasttime);
printf("请输入额定载量");
scanf("%d",&car[i].Fixnumber);
fprintf(fp,"%d",car[i].Fixnumber);
printf("请输入已订票人数");
scanf("%d",&car[i].Fixednumber);
fprintf(fp,"%d",car[i].Fixednumber);
printf("是否继续录入班次信息,“是”请输入1,“否”请按任意键退出");
scanf("%d",&t);
if(t!=1)
welcome();
}
if(fclose(fp))
{
printf("Can not close the file!\n");
exit(0);
} /*关闭文件*/ 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询