#include <stdio.h>
#include <stdlib.h>
#define CNTL_Z '\032' //DOS 文本中的文件结尾标记
#define SLEN 50
int main(int argc, char *argv[])
{
char file[SLEN];
char ch;
FILE *fp;
long count, last;
puts("Enter the name of the file to be processed: ");
gets(file);
if( (fp = fopen(file, "rb")) == NULL ) //只读和二进制模式
{
printf("reverse can't open %s\n", file);
exit(1);
}
fseek(fp, 0L, SEEK_SET); //定位在文件开头处
last = ftell(fp);
printf("fseek(fp, 0L, SEEK_SET) , fteel(p): %d\n", last);
fseek(fp, 0L, SEEK_END); //定位在文件结尾处
last = ftell(fp);
printf("fseek(fp, 0L, SEEK_END) , fteel(p): %d\n", last);
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);
system("PAUSE");
return 0;
} |