输出文件内容,汉字乱码
一个很简单的程序,读取文本文件内容,再倒序输出。如果文件内容只有字母和数字,就能正常输出,如果有汉字,就变乱码了,不会是程序问题,官方源码。。。mingw编译
2015-02-10 23:26
2015-02-10 23:32
2015-02-10 23:47
2015-02-10 23:49
2015-02-11 08:16
程序代码:#include <stdio.h>
#include <stdlib.h>
#define CNTL_Z '\032' /* DOS 文本文件中的文件结尾标记 */
#define SLEN 50
int main (void)
{
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_END); /* 定位文件结尾处 */
last = ftell(fp);
for (count = 1L; count <= last; count++)
{
fseek(fp,-count,SEEK_END); /* 回退 */
ch = getc(fp);
/* 针对 DOS, 在 UNIX 下也可工作 */
if (ch != CNTL_Z && ch != '\r')
putchar(ch);
}
putchar('\n');
fclose(fp);
return 0;
}
2015-02-11 17:05
2015-02-11 17:05
2015-02-11 17:19
2015-02-11 18:41
2015-02-11 19:17