c - 方法不写入文件
问题描述
我正在尝试在 C 中创建一个方法,以便可以写入文件,但我不确定它为什么不起作用。我的代码有什么问题吗?
预先感谢您的帮助。
void writeToFile(Employee *employeeRecords, int count) {
FILE * f = NULL;
fopen("employeeData.txt", "w");
if (f == NULL)
{
printf("Error opening file!\n");
exit(1);
}
const char *text = "Employee data: \n";
fputs(text, f);
for(int l = 0; l < count; l++) {
fprintf(f, "%c", employeeRecords[l].name);
fprintf(f, "%c", employeeRecords[l].surname);
fprintf(f, "%d", employeeRecords[l].age);
fprintf(f, "%lf", employeeRecords[l].salary);
}
fclose(f);
}
解决方案
尝试:
f=fopen("employeeData.txt", "w");
推荐阅读
- blockchain - ParserError:预期的';' 但得到了标识符
- c++ - 有人可以解释我在解决这个问题的方法中做错了什么吗
- c - Socket编程聊天应用
- python - Numba:如何将 str 转换为 int?
- sql - 如何将存储过程的结果放在视图的新列中?
- javascript - node nftint.js (node:2540) UnhandledPromiseRejectionWarning: Error: Transaction has been reverted by the EVM:
- node.js - 用于后端的 Node.js
- javascript - [Vue 警告]:v-on 处理程序中的错误:“TypeError: Object(...)(...).httpsCallable(...).then 不是函数”
- java - Sonarlink 插件未在 Eclipse 中安装
- python - 仅在 pygame 中敌人活着时播放音效