我想将float更改为char并将其传递给函数作为参数以保存在文件中。 数据未保存在文件中。
如代码中所示,我尝试将数据从float转换为char,然后获取此数据并将其放入文件中。然后关闭此文件。
void file_create (char data[DATA_SIZE]) {
FILE *fptr;
fptr = fopen("D:\\backup01\\Downloads\\Prog\\userdata.txt", "w");
if (fptr==NULL) {
printf("file could not be created or open \n\n");
exit (EXIT_FAILURE);
}
else {
fprintf(data, "%f", mat); /*convert "mat" to char and "mat" is a float 2d array declared as global variable and its data is collected from an other function*/
gets(data);
fputs(data, fptr);
fclose(fptr);
printf("Your data has been saved in the file correctly\n\n");
}
}
无错误消息。文件已创建但没有数据。