回车换行的fgetc读取
2016-05-05 10:24 flyfish163 阅读(1775) 评论(0) 编辑 收藏 举报
int readfile(const char * szFile)
{
FILE *fp;
char ch;
char achByteDisp[3]={0,0,0};
BOOLEAN bIsSecondCh = false;
long val;
int linechange=0;
if((fp=fopen(szFile,"rt"))==NULL)
{
printf("\nCannot open file strike any key exit!");
getchar();
return 1;
}
ch=fgetc(fp);
while(ch!=EOF)
{
/*回车换行,0D0A,WINDOWS下一次读入,即\n,LINUX下需要分两次读入0x0d, 0x0a*/
/*if (ch!='\n') */ /*windows*/
if (ch != 13 && ch != 10) /*linux*/
{
if(!bIsSecondCh) //第一个字符
{
achByteDisp[0]=ch;
bIsSecondCh = true;
}
else //第二个字符
{
achByteDisp[1]=ch;
val = strtol(achByteDisp, NULL, 16);
gbyBuff[gdwByteNum++] = (BYTE)val;
bIsSecondCh = false;
}
}
ch=fgetc(fp);
}
fclose(fp);
printf("readin %s gdwByteNum %d\n", szFile, gdwByteNum);
return 0;
}