我需要将整数打印到文件中。我将在下面发布代码。此代码的输出是一个空文件,它不包含整数。
FILE *out1;
out1 = fopen(outfile, "w");
if( out1 == NULL )
{
perror("Error while opening the output file.\n");
exit(EXIT_FAILURE);
}
int paste = noptr->no;
printf("message received %d\n", paste);
fprintf(out1,"%d\n", paste);
printf("printed!\n");
fclose(out1);
答案 0 :(得分:0)
您的代码适用于我。也许您的int
为0并且您在文本编辑器中打开文件。检查输出文件大小。
答案 1 :(得分:-1)
如果您愿意使用 name outfile写入文件,
out1 = fopen("outfile", "w");