首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

倒序输出,为何重复

2013-04-20 
倒序输出,为什么重复?[解决办法]按照你的意思,应该这样#includestdio.h#includestdlib.h#define CNTL_

倒序输出,为什么重复?

                            
[解决办法]
按照你的意思,应该这样
#include<stdio.h>
#include<stdlib.h>
#define CNTL_Z '\032'
#define SLEN 50
int main(void)
{
char file[SLEN];
char ch;
FILE *fp;
long count,last;

puts("Enter the name of the file to processed:");
gets(file);
if((fp=fopen(file,"rb"))==NULL)
{
printf("reverse can't open %s\n",file);
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);
else if(ch=='\r')
putchar('\n');
else 
putchar(ch);
}
putchar('\n');
fclose(fp);
return 0;
}

热点排行