经过今天的验证,终于知道linux文件的换行符为LF,ascii Hex为0A,Dec为10, 在进行条件判断可以使用 if(ch == ‘\n’)的写法.
实验代码
#include <stdio.h>
#include <stdlib.h>
long sizeByFile(const char *filename,char *mode)
{
long size=0;
FILE *fp = NULL;
fp = fopen(filename,mode);
if(NULL == fp)
{
printf("file open error\n");
exit(0);
}
fseek(fp,0,SEEK_END);
size = ftell(fp);
rewind(fp);
fclose(fp);
return size;
}
int main()
{
long size = sizeByFile("aa.txt","r");
printf("%d\n",size);
FILE *fp = fopen("aa.txt","r");
char ch[20]={0,};
int len = fread(ch,1,20,fp);
printf("%d\n",len);
int i=0;
for(i=0;i<10;i++)
{
printf("%x ",ch[i]);
if(5 == i) printf("\n");
}
printf("\n%x\n",'\n');
}