我正在尝试读取二进制文件及其内容。
/*aoObj.fb is the pointer of the file (e.x. FILE *fp)*/
char ch;
aoObj.fp = fopen(aoObj.f_name, "rb");
if (aoObj.fp == NULL)
{
perror("Error while opening the file.\n");
exit(EXIT_FAILURE);
}
/* /\*list all strings *\/ */
printf("\n\nThe content of the file: \n");
while ((ch = fgetc(aoObj.fp)) != EOF)
printf("%c", ch);
fclose(aoObj.fp);
(void) opt_free(&aoObj);
return 0;
}
但是当我打印此文件的内容时遇到了问题,因为只有输入的第一个字符不能正确打印,如下所示:
我可以知道为什么会这样吗?
编辑:所有正在读取的变量都声明为STRINGS
您将ch
声明为char
,但应将其声明为int
。