【发布时间】:2014-05-21 15:10:44
【问题描述】:
我正在尝试读取一些图像并将信息复制到 3D 缓冲区(矩阵缓冲区,其中每个矩阵中的信息是来自图像的信息)。要使用 fopen 打开图像,我需要图像的名称(例如“pt_176118_x_0600_cand.pgm”)。对于读取多个文件,数字 0600(开始 = 600)将增加一个步长 = 5 直到达到 02400。所以我需要连接“pt_176118_x_”、一个数字和“_cand.pgm”。我的问题是如何做到这一点,更准确地说,如何将数字转换为字符串,然后,如何转换或表示该字符串以便 fopen 可以识别它
虽然我在这里搜索过合适的解决方案,但似乎没有一个适合这种情况。 我的代码是:
FILE *ident;
for(k=0;k<360;k++)
{ printf("\r Read slice: %d (real: %d)",k,start + step*k);
num = start+step*k;
sprintf(outString,"%s%d%s","pt_176118_x_%d",num,"_cand_test.pgm");
if( ( ident = fopen(outString,"rb")) == NULL)
{
printf(" Error opening file %s \n",outString);
exit(1);
}
}
【问题讨论】:
-
您是否尝试过使用 to_string() 函数?
-
为什么不简单地
sprintf(outString,"pt_176118_x_%d_cand_test.pgm",num);?? -
对于这个变种我得到错误:访问冲突写入位置