C语言使用fgetc读取文件出错。
#include<stdio.h>
#include<string.h>
#include<conio.h>
int main() {
FILE *fp;
unsigned char ch;
int num[8];
int count = 0;
fp = fopen("2.txt","r");
while( (ch = fgetc(fp)) != 255){
for(int i=0;i<8;i++){
num[i] = ch>>(7-i)&1;
printf("%d",num[i]);
}
printf(" ");
if (++count == 8) {
printf("\n");
count = 0;
}
getch();
}
fclose(fp);
}
读取的文件在这里:www.ewinds.pw/2.txt
很奇怪,用自己写的程序读取文件,结果是这样的:
用ultreaEdit读取出来结果如下:
想要知道为什么读取到第二十一个字节,一直往后,全部变成了1111 1111.
求大家指点,不甚感激
fp = fopen("2.txt","r
b
");结果