文件读取问题
不知道怎么回事,我写了个文件读取的小程序,读取到一定的行数后读出来的数据是错误的。大家看看是怎么回事。代码:
#include<stdio.h>
int main()
{
FILE *fp;
FILE *fp_out;
//char gch;
char ch_x[] = {'0','1','2','3',
'4','5','6','7',
'8','9','a','b',
'c','d','e','f'};
int k;
int i;
char p_ch=0x1;
char ch;
fp=fopen("shudepb.exe","r");
if(fp==NULL)
{
printf("file open error !!");
//exit(0);
}
fp_out=fopen("out.txt","w");
if(fp_out==NULL)
{
printf("file open error !!");
//exit(0);
}
k=0;
do
{
ch=fgetc(fp);
fprintf(fp_out,"%d\t%c%c\t",k,ch_x[(ch&0x00f0)>>4],ch_x[ch&0x000f]);
for(i=7;i>=0;i--)
{ if((p_ch<<i)&ch)
fprintf(fp_out,"1");
else fprintf(fp_out,"0");
}
fprintf(fp_out,"\n");
k++;
}while(k!=5000);
}