【发布时间】:2014-04-29 17:31:50
【问题描述】:
在打印出我读入数组的文件后,我得到了一些额外的垃圾字符。
这是我的代码
fp = fopen("load.txt", "r");
if (fp == NULL)
{
perror("Exiting, an error occured while opening\n");
exit(EXIT_FAILURE);
}
while((ch = fgetc(fp)) != EOF)
{
load[i++] = ch;
}
fclose(fp);
for(i = 0; i < 100; ++i)
{
printf("%c", load[i]);
}
样本输出
The quick brown fox jumped over the lazy dog.
���������0LãUˇ���∞4
����������@LãUˇ��������������
注意到句子后面的所有垃圾了吗?我不确定是什么原因造成的。
提前感谢您的帮助
【问题讨论】:
-
请贴出完整的相关代码。
-
请发布
load声明。 -
您是否正在阅读大约 45 个字符(“The quick brown fox jumped over the lazy dog.”的长度)并打印 100 个字符?