在 for 循环中使用 C 的 fwrite
我搜索了该网站,但没有找到我的问题的答案。
我的程序输出一个图像,我想保存到不同的文件,每个图像在循环迭代后生成。
我保存文件的代码是这样的,
FILE *fobjecto;
if ((fobjecto = fopen ("OSEM.ima", "wb")) != NULL)
{
printf("Writing reconstructed image file");
fwrite (objecto, sizeof(float), (detectorXDim)*detectorYDim*(NSlices-1), fobjecto);
fclose (fobjecto);
}
else
printf("Reconstructed image file could not be saved");
我想在输出文件的名称中添加一个整数变量,我尝试过使用“+”和“,”,但我无法解决它。
提前致谢
I have searched the site and I haven't found an answer to my problem.
My program outputs an image, and I want to save to a different file, each image produced after an cycle iteration.
My code to save files is this
FILE *fobjecto;
if ((fobjecto = fopen ("OSEM.ima", "wb")) != NULL)
{
printf("Writing reconstructed image file");
fwrite (objecto, sizeof(float), (detectorXDim)*detectorYDim*(NSlices-1), fobjecto);
fclose (fobjecto);
}
else
printf("Reconstructed image file could not be saved");
I want to add one integer variable to the output file's name, I have tried playing with "+" and "," but I could not solve it.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您将需要一些格式化输出操作,例如
sprintf
(或者更好的是它的安全孪生snprintf
):You will need some formatted output operation like
sprintf
(or even better its safe twinsnprintf
):在打开文件之前构造文件名:
construct the file name before you open it: