方法不写入文件
Method not writing to file
我正在尝试在 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");
我正在尝试在 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");