c - 文件中的内容在c程序中不存在
问题描述
如何制作文件,我尝试在c中制作file.txt但出现错误,我编写的程序成功执行,但在文件或记事本中内容不存在。
这是我想要输入到 file.txt 的代码片段:
int a,b,c,d,e = 0,f = 0;
int check,check2,check3;
int *fptr;
fptr = fopen("file.txt","w");
printf("\nenter the amount of food to be purchased : ");
check=scanf("%d", &b);
printf("\n");
if (check != 0) {
for (a=1; a<=b; a++){
printf("the price of food of- %d \t : ",a);
check2=scanf("%d", &c);
printf("\n");
if (check2==0) {
printf("Please enter in numeric !!\n");
while ((getchar()) != '\n');
system("PAUSE");
goto cashier;
}
printf("the amount ordered \t : ");
check3=scanf("%d", &d);
printf("\n");
if (check3==0) {
printf("Please enter in numeric !!\n");
while ((getchar()) != '\n');
system("PAUSE");
goto cashier;
}
e=c*d;
f+=e;
}
printf("total price of food \t : Rp.%d",f);
printf("\n");
char isTrue;
printf("\n\nPush [Y] to save a copy from your payment [T]\nTo Out\n:");
scanf(" %c",&isTrue);
if(isTrue == 'y' || isTrue == 'Y'){
fprintf(fptr, "the food you buy as much : %d\n", b);
fprintf(fptr, "total price of food : %d\n", f);
fclose(fptr);
goto cashier;
}
我应该怎么做才能修复这个程序?
我想要这个 fprintf(fptr, "the food you buy as much : %d\n", b); 将执行并打印它:"write the food you buy as much" 在我的记事本中。也在我的记事本文件中。 txt 我之前没有写任何东西,而且我之前也没有创建这个 file.txt
解决方案
推荐阅读
- python-3.x - Python3 日期时间(增量)到秒(包括天)
- java - 如何在不创建单独的字符串数组并向其添加单独转换的 int 数组项的情况下将整数数组转换为字符串数组?
- android - 为什么我在 Unity2020 的 XR 插件管理中尝试分配 ARCore 时出现 XR 插件管理错误?
- f# - F#:设计或不设计具有相互可靠的记录类型
- python - 比较熊猫数据框中的条目
- python - 如何从 Python 中的数组中获取唯一值和重复值?
- debugging - GDB `run` 命令因“无法插入断点 1”而失败。
- node.js - 使用官方 Node 镜像的 Dockerized Node API
- twilio - twilio计费不同的不同号码
- python - 使用 PyQt5 和 GNURadio 避免退出代码 -1073741819 (0xC0000005)