在线免费解答网站怎么建,河北公司网站建设效果,wordpress拿站,在线链接当我们在使用Window操作系统的时候#xff0c;可能使用最多的文本格式就是txt了#xff0c;可是当我们将Window平台下的txt文本文档复制到Linux平台下查看时#xff0c;发现原来的中文所有变成了乱码。没错#xff0c; 引起这个结果的原因就是两个平台下#xff0c;编辑器…当我们在使用Window操作系统的时候可能使用最多的文本格式就是txt了可是当我们将Window平台下的txt文本文档复制到Linux平台下查看时发现原来的中文所有变成了乱码。没错 引起这个结果的原因就是两个平台下编辑器对默认的编码格式是不一样的 在Window平台下。Notepad的默认编码是ASCII码或者GBK而在Linux平台下默认的是UTF-8中文环境的情况编码的不同导致了原来文档中的中文变成了乱码。 解决的方法 使用iconv命令将文档的编码进行转换就可以。 iconv默认情况下是没有被安装的。以下简介下iconv的安装过程 1. 下载http://www.gnu.org/software/libiconv/#TOCdownloading 2. 安装 下载完毕后切换到下载文件夹先进行解压$tar -xzvf libiconv-1.14.tar.gz 然后进入解压后的文件里 $cd libiconv-1.14_2查看当中的README文件我们能够看到安装步骤当然假设您熟悉源代码的安装这步全然能够省略^-^$ ./configure --prefix/usr/local
$ make
$ make install 3. 命令学习 该工具安装完毕后肯定要先了解下这个命令的使用方法吧。这个没什么可说的$iconv --help我们会看到以下的内容Usage: iconv [OPTION...] [FILE...]
Convert encoding of given files from one encoding to another.Input/Output format specification:-f, --from-codeNAME encoding of original text-t, --to-codeNAME encoding for outputInformation:-l, --list list all known coded character setsOutput control:-c omit invalid characters from output-o, --outputFILE 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 原编码 -t 目标编码 要转换的文件 4. 编码转换 学会了编码的转化。我们就举了样例示范一下$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文件就会发现原来的中文显示正常了^-^ 注意 假设不出意外的话。上面的安装步骤可没有那么顺利。在make的时候会提示以下的错误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 0300srclib/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 isalways 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内容中的表示新增的内容。-表示删除的内容! 那我们仅仅要进行例如以下操作就可以解决问题 1. 切换到srclib文件夹下$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 3. 保存退出。然后再进行make, make install便可顺利安装^-^ 參考资料http://forum.z27315.com/topic/15662-%E8%A7%A3%E5%86%B3%E7%BC%96%E8%AF%91libiconv%E6%97%B6%E7%9A%84gets-undeclared-here%E9%94%99%E8%AF%AF/转载于:https://www.cnblogs.com/liguangsunls/p/7122605.html