为什么这个程序要用到ch!='\r'?
下面这个程序是将一个文件反序读取。为什么要用if(ch!=CNTL_Z && ch!='\r')作为结束标志,另外文件结尾不是用EOF吗?这个程序在预定义中用#define CNTL_Z '\032'来表示文件结束标志,为什么?
#include "stdafx.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#define CNTL_Z '\032' /* dos 文本文件中的文件结尾标记*/
#define SLEN 50
int main(void)
{
char file[SLEN];
FILE *fp;
char ch;
long count, last;
printf("Please input the name of the file:");
gets(file);
fp = fopen(file, "rb");
if(fp == NULL)
{
printf("Can not open the file.\n");
exit(1);
}
fseek(fp, 0L, SEEK_END);
last = ftell(fp);
for(count=1L; count<=last; count++)
{
fseek(fp, -count, SEEK_END);
ch = getc(fp);
if(ch!=CNTL_Z && ch!='\r')
{
putchar(ch);
}
}
putchar('\n');
fclose(fp);
return 0;
}