【发布时间】:2014-03-12 02:19:00
【问题描述】:
编辑:看来我已经修好了...
header[3] = str
strcpy(header[3], str)
这些行在使用 printf 时产生相同的输出,但显然 fprintf 只像 strcpy。
这是我的代码:
int pgmWrite( const char **header, const int **pixels, int numRows, int numCols, FILE *out )
{
int i, j;
printf("%s\n\n", header[3]);
for(i = 0; i < 4; i++)
fprintf(out, "%s", header[i]);
printf("success in WRITE\n\n\n\n\n");
for(j = 0; j < numRows; j++)
{
for(i = 0; i < numCols; i++)
fprintf(out, "%d ", pixels[i][j]);
fprintf(out, "\n");
}
}
在printf 语句中,header[3] 输出为 237。
在fprintf 语句中,header[3] 被输出为乱码 unicode 字符。
如果有人想要我可以添加完整程序(300 行)的怪物,如果你真的想看看一切都在做什么......
编辑:这是我发生错误时的输出(所有这些输出都来自上述函数)
P2
# baboon.pgma created by PGMA_IO::PGMA_WRITE.
512 512
s· _ . .
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
(plus a couple thousand more zeroes for the rest of the image)
产生错误:./a.out -E 75 ./baboon.ascii.pgm testBaboon.pgm
【问题讨论】:
-
没有人想要完整的程序。我们想要一个能够重现问题的简短程序。
-
当您说“输出是乱码 unicode 字符”时,您是如何确定的? (提示,notepad.exe 不是确定这一点的可靠方法)你是如何打开
out的? -
我们需要查看
FILE* out的声明,因为鉴于明显的乱码输出,这可能是根本原因之一。 -
我打开了两种方式。 gedit 和(因为我的输出是一个 .pgm 文件)在照片查看器中。照片查看器无法显示它,当我在 gedit 中打开它时,唯一“搞砸 unicode”的部分是一行。该行指定文件的最大白色“强度”。如果我在程序的其他地方编辑它,我可以完美地打印出新值,直到我尝试打印到文件。
-
也许
header[3]没问题,header[0]等有乱码。您必须发布一个创建乱码的完整程序,以便其他人可以重现它。