标签:linux txt iconv gets undeclared here 乱码
当我们在使用Window操作系统的时候,可能使用最多的文本格式就是txt了,但是当我们将Window平台下的txt文本文档拷贝到Linux平台下查看时,发现原来的中文全部变成了乱码。没错, 引起这个结果的原因就是两个平台下,编辑器对默认的编码格式是不一样的:$tar -xzvf libiconv-1.14.tar.gz
然后进入解压后的文件中
$cd libiconv-1.14_2查看其中的README文件,我们可以看到安装步骤:(当然,如果您熟悉源码的安装,这步完全可以省略^-^)
$ ./configure --prefix=/usr/local $ make $ make install
$iconv --help我们会看到下面的内容:
Usage: iconv [OPTION...] [FILE...] Convert encoding of given files from one encoding to another. Input/Output format specification: -f, --from-code=NAME encoding of original text -t, --to-code=NAME encoding for output Information: -l, --list list all known coded character sets Output control: -c omit invalid characters from output -o, --output=FILE output file -s, --silent suppress warnings --verbose print progress information -?, --help Give this help list --usage Give a short usage message -V, --version Print program version Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options.说的很明白,就是按照下面的格式进行转换:
$iconv -f gbk -t utf8 test.txt命令执行完成后,你发现原来test.txt中的中文正常显示了,但是打开原来的文件,却发现还是乱码,这个Easy,我们将输出的内容输入到文件中即可。
$iconv -f gbk -t utf8 test.txt -o test或者执行下面的命令:
$iconv -f gbk -t utf8 test.txt < test此时我们打开这个test文件就会发现,原来的中文显示正常了^-^
n file included from progname.c:26:0: ./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function) _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); ^ make[2]: *** [progname.o] Error 1 make[2]: Leaving directory `/home/freeman/Downloads/libiconv-1.14_2/srclib' make[1]: *** [all] Error 2 make[1]: Leaving directory `/home/freeman/Downloads/libiconv-1.14_2/srclib' make: *** [all] Error 2这个这个软件本身存在的一个Bug,通过Google,发现一个解决该问题的补丁,内容如下:
--- srclib/stdio.in.h.orig 2011-08-07 16:42:06.000000000 +0300 +++ srclib/stdio.in.h 2013-01-10 15:53:03.000000000 +0200 @@ -695,7 +695,9 @@ /* It is very rare that the developer ever has full control of stdin, so any use of gets warrants an unconditional warning. Assume it is always declared, since it is required by C89. */ -_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); +#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16) + _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); +#endif #endifPS:内容中的"+"表示新增的内容,"-"表示删除的内容!
$cd srclib
2. 修改stdio.in.h文件:
$gedit stdio.in.h通过搜索,定位到_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");这一行,然后在这一行的前后加上条件编译即可,修改后的内容如下:
#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16) _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); #endif
标签:linux txt iconv gets undeclared here 乱码
原文地址:http://blog.csdn.net/jhg1204/article/details/40711153