﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-The power of C, the power of MD-随笔分类-C/C++</title><link>http://www.cppblog.com/yui/category/14344.html</link><description>A problem is a chance to do your best</description><language>zh-cn</language><lastBuildDate>Mon, 06 Sep 2010 16:55:03 GMT</lastBuildDate><pubDate>Mon, 06 Sep 2010 16:55:03 GMT</pubDate><ttl>60</ttl><item><title>使用gSOAP开发实例(8) 自定义header实现用户名令牌认证(Usernametoken Authentication)</title><link>http://www.cppblog.com/yui/archive/2010/09/06/126056.html</link><dc:creator>roy</dc:creator><author>roy</author><pubDate>Mon, 06 Sep 2010 15:39:00 GMT</pubDate><guid>http://www.cppblog.com/yui/archive/2010/09/06/126056.html</guid><wfw:comment>http://www.cppblog.com/yui/comments/126056.html</wfw:comment><comments>http://www.cppblog.com/yui/archive/2010/09/06/126056.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yui/comments/commentRss/126056.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yui/services/trackbacks/126056.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 上一节介绍了怎样实现基本认证(Basic Authentication，以下简称basic方式)，望文生义，也就是最简单的用户验证方式，本节稍微深入一些，介绍用户名令牌认证(Usernametoken Authentication，以下简称usernametoken方式)。&nbsp;&nbsp;<a href='http://www.cppblog.com/yui/archive/2010/09/06/126056.html'>阅读全文</a><img src ="http://www.cppblog.com/yui/aggbug/126056.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yui/" target="_blank">roy</a> 2010-09-06 23:39 <a href="http://www.cppblog.com/yui/archive/2010/09/06/126056.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用gSOAP开发实例(7) 基于HTTPS的基本认证(Basic Authentication)</title><link>http://www.cppblog.com/yui/archive/2010/09/04/125886.html</link><dc:creator>roy</dc:creator><author>roy</author><pubDate>Sat, 04 Sep 2010 10:51:00 GMT</pubDate><guid>http://www.cppblog.com/yui/archive/2010/09/04/125886.html</guid><wfw:comment>http://www.cppblog.com/yui/comments/125886.html</wfw:comment><comments>http://www.cppblog.com/yui/archive/2010/09/04/125886.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yui/comments/commentRss/125886.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yui/services/trackbacks/125886.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;<a href='http://www.cppblog.com/yui/archive/2010/09/04/125886.html'>阅读全文</a><img src ="http://www.cppblog.com/yui/aggbug/125886.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yui/" target="_blank">roy</a> 2010-09-04 18:51 <a href="http://www.cppblog.com/yui/archive/2010/09/04/125886.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用gSOAP开发实例(6) 在HP-UX下编译gSOAP-2.7.17</title><link>http://www.cppblog.com/yui/archive/2010/09/03/125840.html</link><dc:creator>roy</dc:creator><author>roy</author><pubDate>Fri, 03 Sep 2010 15:02:00 GMT</pubDate><guid>http://www.cppblog.com/yui/archive/2010/09/03/125840.html</guid><wfw:comment>http://www.cppblog.com/yui/comments/125840.html</wfw:comment><comments>http://www.cppblog.com/yui/archive/2010/09/03/125840.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/yui/comments/commentRss/125840.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yui/services/trackbacks/125840.html</trackback:ping><description><![CDATA[<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">gSOAP</span>
<span style="font-family: 宋体;" lang="ZH-CN">号称是跨平台的工具包，不过毕竟是属于</span>
<span style="font-family: &quot;Courier New&quot;;">g</span>
<span style="font-family: 宋体;" lang="ZH-CN">字头的，如果没有了一系列</span>
<span style="font-family: &quot;Courier New&quot;;">GNU</span>
<span style="font-family: 宋体;" lang="ZH-CN">组件的支持，在其他类</span>
<span style="font-family: &quot;Courier New&quot;;">Unix</span>
<span style="font-family: 宋体;" lang="ZH-CN">系统编译也会遇到不少困难。</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">gSOAP</span>
<span style="font-family: 宋体;" lang="ZH-CN">的</span>
<span style="font-family: &quot;Courier New&quot;;">README</span>
<span style="font-family: 宋体;" lang="ZH-CN">说得也不是很清楚，只提到依赖于这些组件：</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">1. <strong>Automake</strong>
tools (make and GNU m4) to
configure and build</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">2. <strong>Bison</strong>
http://www.gnu.org/software/bison
or the alternative Yacc</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">3. <strong>Flex</strong>
http://flex.sourceforge.net</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">4. <strong>OpenSSL</strong>
(for optional HTTPS)
http://www.openssl.org</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">5. <strong>Zlib</strong>
(for optional compression)
http://www.zlib.net</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">6. <strong>Pthreads</strong>
or win32 threads (optional)</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal"><span style="font-family: 宋体;" lang="ZH-CN">实际上，我在</span>
<span style="font-family: &quot;Courier New&quot;;">HP-UX</span>
<span style="font-family: 宋体;" lang="ZH-CN">下编译</span>
<span style="font-family: &quot;Courier New&quot;;">gSOAP</span>
<span style="font-family: 宋体;" lang="ZH-CN">的时候发现，要成功编译，还需要安装</span>
<span style="font-family: &quot;Courier New&quot;;">autoconf</span>
<span style="font-family: 宋体;" lang="ZH-CN">、</span>
<span style="font-family: &quot;Courier New&quot;;">gawk</span>
<span style="font-family: 宋体;" lang="ZH-CN">和</span>
<span style="font-family: &quot;Courier New&quot;;">make</span>
<span style="font-family: 宋体;" lang="ZH-CN">，为解决中文乱码问题，还需要安装</span>
<span style="font-family: &quot;Courier New&quot;;">libiconv</span>
<span style="font-family: 宋体;" lang="ZH-CN">。虽然原系统就有</span>
<span style="font-family: &quot;Courier New&quot;;">awk</span>
<span style="font-family: 宋体;" lang="ZH-CN">和</span>
<span style="font-family: &quot;Courier New&quot;;">make</span>
<span style="font-family: 宋体;" lang="ZH-CN">，但是由于版本问题，编译时出错。所以，建议大家编译最新版的</span>
<span style="font-family: &quot;Courier New&quot;;">gSOAP-2.7.17</span>
<span style="font-family: 宋体;" lang="ZH-CN">时，按一下顺序安装组件：</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 39.75pt; text-indent: -21.75pt;"><!-- [if !supportLists]--><span style="font-family: &quot;Courier New&quot;;"><span>1.<span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;
</span>
</span>
</span>
<!-- [endif]--><strong><span style="font-family: &quot;Courier New&quot;;">autoconf-2.66</span>
</strong>
<span style="font-family: &quot;Courier New&quot;;"> (<a href="http://ftp.gnu.org/gnu/autoconf/">http://ftp.gnu.org/gnu/autoconf/</a>
)</span>
</p>
<p class="MsoNormal" style="margin-left: 0.25in;"><span style="font-family: &quot;Courier New&quot;;">autoconf</span>
<span style="font-family: 宋体;" lang="ZH-CN">是一个用于生成可以自动地配置软件源代码包以适应多种</span>
<span style="font-family: &quot;Courier New&quot;;">Unix</span>
<span style="font-family: 宋体;" lang="ZH-CN">类系统的</span>
<span style="font-family: &quot;Courier New&quot;;">shell</span>
<span style="font-family: 宋体;" lang="ZH-CN">脚本的工具。</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 39.75pt; text-indent: -21.75pt;"><!-- [if !supportLists]--><span style="font-family: &quot;Courier New&quot;;"><span>2.<span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;
</span>
</span>
</span>
<!-- [endif]--><strong><span style="font-family: &quot;Courier New&quot;;">automake-1.10</span>
</strong>
<span style="font-family: &quot;Courier New&quot;;"> (<a href="http://ftp.gnu.org/gnu/automake/">http://ftp.gnu.org/gnu/automake/</a>
)</span>
</p>
<p class="MsoNormal" style="margin-left: 0.25in;"><span style="font-family: &quot;Courier New&quot;;">automake</span>
<span style="font-family: 宋体;" lang="ZH-CN">是一个从文件</span>
<span style="font-family: &quot;Courier New&quot;;">Makefile.am</span>
<span style="font-family: 宋体;" lang="ZH-CN">自动生成</span>
<span style="font-family: &quot;Courier New&quot;;">Makefile.in</span>
<span style="font-family: 宋体;" lang="ZH-CN">的工具。每个</span>
<span style="font-family: &quot;Courier New&quot;;">Makefile.am</span>
<span style="font-family: 宋体;" lang="ZH-CN">基本上是一系列</span>
<span style="font-family: &quot;Courier New&quot;;">make</span>
<span style="font-family: 宋体;" lang="ZH-CN">的宏定义（</span>
<span style="font-family: &quot;Courier New&quot;;">make</span>
<span style="font-family: 宋体;" lang="ZH-CN">规则也会偶尔出现）。生成的</span>
<span style="font-family: &quot;Courier New&quot;;">Makefile.in</span>
<span style="font-family: 宋体;" lang="ZH-CN">服从</span>
<span style="font-family: &quot;Courier New&quot;;">GNU Makefile</span>
<span style="font-family: 宋体;" lang="ZH-CN">标准。</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 39.75pt; text-indent: -21.75pt;"><!-- [if !supportLists]--><span style="font-family: &quot;Courier New&quot;;"><span>3.<span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;
</span>
</span>
</span>
<!-- [endif]--><strong><span style="font-family: &quot;Courier New&quot;;">m4-1.4.14</span>
</strong>
<span style="font-family: &quot;Courier New&quot;;"> (<a href="http://ftp.gnu.org/gnu/m4/">http://ftp.gnu.org/gnu/m4/</a>
)</span>
</p>
<p class="MsoNormal" style="margin-left: 0.25in;"><span style="font-family: &quot;Courier New&quot;;">m4</span>
<span style="font-family: 宋体;" lang="ZH-CN">是一个宏处理器。</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 39.75pt; text-indent: -21.75pt;"><!-- [if !supportLists]--><span style="font-family: &quot;Courier New&quot;;"><span>4.<span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;
</span>
</span>
</span>
<!-- [endif]--><strong><span style="font-family: &quot;Courier New&quot;;">gawk-3.1.8</span>
</strong>
<span style="font-family: &quot;Courier New&quot;;"> (<a href="http://ftp.gnu.org/gnu/gawk/">http://ftp.gnu.org/gnu/gawk/</a>
)</span>
</p>
<p class="MsoNormal" style="margin-left: 0.25in;"><span style="font-family: &quot;Courier New&quot;;">awk</span>
<span style="font-family: 宋体;" lang="ZH-CN">地球人都知道。</span>
<span style="font-family: &quot;Courier New&quot;;">HP-UX</span>
<span style="font-family: 宋体;" lang="ZH-CN">自带的</span>
<span style="font-family: &quot;Courier New&quot;;">awk</span>
<span style="font-family: 宋体;" lang="ZH-CN">不是</span>
<span style="font-family: &quot;Courier New&quot;;">GNU</span>
<span style="font-family: 宋体;" lang="ZH-CN">的，编译</span>
<span style="font-family: &quot;Courier New&quot;;">gSOAP</span>
<span style="font-family: 宋体;" lang="ZH-CN">时执行某些语句出错，因此在编译</span>
<span style="font-family: &quot;Courier New&quot;;">gSOAP</span>
<span style="font-family: 宋体;" lang="ZH-CN">时要使用</span>
<span style="font-family: &quot;Courier New&quot;;">GNU</span>
<span style="font-family: 宋体;" lang="ZH-CN">新版本。</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 39.75pt; text-indent: -21.75pt;"><!-- [if !supportLists]--><span style="font-family: &quot;Courier New&quot;;"><span>5.<span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;
</span>
</span>
</span>
<!-- [endif]--><strong><span style="font-family: &quot;Courier New&quot;;">make-3.81</span>
</strong>
<span style="font-family: &quot;Courier New&quot;;"> (<a href="http://ftp.gnu.org/gnu/make/">http://ftp.gnu.org/gnu/make/</a>
)</span>
</p>
<p class="MsoNormal" style="margin-left: 0.25in;"><span style="font-family: &quot;Courier New&quot;;">make</span>
<span style="font-family: 宋体;" lang="ZH-CN">也是地球人都知道。</span>
<span style="font-family: &quot;Courier New&quot;;">HP-UX</span>
<span style="font-family: 宋体;" lang="ZH-CN">自带的</span>
<span style="font-family: &quot;Courier New&quot;;">make</span>
<span style="font-family: 宋体;" lang="ZH-CN">编译</span>
<span style="font-family: &quot;Courier New&quot;;">gSOAP</span>
<span style="font-family: 宋体;" lang="ZH-CN">时会出错。</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 39.75pt; text-indent: -21.75pt;"><!-- [if !supportLists]--><span style="font-family: &quot;Courier New&quot;;"><span>6.<span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;
</span>
</span>
</span>
<!-- [endif]--><strong><span style="font-family: &quot;Courier New&quot;;">bison-2.4</span>
</strong>
<span style="font-family: &quot;Courier New&quot;;"> (<a href="http://ftp.gnu.org/gnu/bison/">http://ftp.gnu.org/gnu/bison/</a>
)</span>
</p>
<p class="MsoNormal" style="margin-left: 0.25in;"><span style="font-family: 宋体;" lang="ZH-CN">语法分析生成器。</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 39.75pt; text-indent: -21.75pt;"><!-- [if !supportLists]--><span style="font-family: &quot;Courier New&quot;;"><span>7.<span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;
</span>
</span>
</span>
<!-- [endif]--><strong><span style="font-family: &quot;Courier New&quot;;">flex-2.5.35</span>
</strong>
<span style="font-family: &quot;Courier New&quot;;"> (<a href="http://flex.sourceforge.net/">http://flex.sourceforge.net/</a>
)</span>
</p>
<p class="MsoNormal" style="margin-left: 0.25in;"><span style="font-family: 宋体;" lang="ZH-CN">词法分析生成器。</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 39.75pt; text-indent: -21.75pt;"><!-- [if !supportLists]--><span style="font-family: &quot;Courier New&quot;;"><span>8.<span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;
</span>
</span>
</span>
<!-- [endif]--><strong><span style="font-family: &quot;Courier New&quot;;">zlib-1.2.5</span>
</strong>
<span style="font-family: &quot;Courier New&quot;;"> (<a href="http://www.zlib.net/">http://www.zlib.net/</a>
)</span>
</p>
<p class="MsoNormal" style="margin-left: 0.25in;"><span style="font-family: &quot;Courier New&quot;;">gzip</span>
<span style="font-family: 宋体;" lang="ZH-CN">和</span>
<span style="font-family: &quot;Courier New&quot;;">LZW</span>
<span style="font-family: 宋体;" lang="ZH-CN">压缩库。</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 39.75pt; text-indent: -21.75pt;"><!-- [if !supportLists]--><span style="font-family: &quot;Courier New&quot;;"><span>9.<span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;
</span>
</span>
</span>
<!-- [endif]--><strong><span style="font-family: &quot;Courier New&quot;;">libiconv-1.13.1</span>
</strong>
<span style="font-family: &quot;Courier New&quot;;"> (<a href="http://ftp.gnu.org/pub/gnu/libiconv/">http://ftp.gnu.org/pub/gnu/libiconv/</a>
)</span>
</p>
<p class="MsoNormal" style="margin-left: 0.25in;"><span style="font-family: 宋体;" lang="ZH-CN">字符编码转换工具，上一节有介绍。</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 0.25in;"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal" style="margin-left: 0.25in;"><span style="font-family: &quot;Courier New&quot;;">openssl</span>
<span style="font-family: 宋体;" lang="ZH-CN">原来就已经有，无需安装。如果没有或者版本很低，可以到这里下载：</span>
<span style="font-family: &quot;courier new&quot;;" lang="ZH-CN"> </span>
<span style="font-family: &quot;Courier New&quot;;"><a href="http://www.openssl.org/source/">http://www.openssl.org/source/</a>
</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal"><span style="font-family: 宋体;" lang="ZH-CN">补充事项：</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 39.75pt; text-indent: -21.75pt;"><!-- [if !supportLists]--><span style="font-family: &quot;Courier New&quot;;"><span>1.<span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;
</span>
</span>
</span>
<!-- [endif]--><strong><span style="font-family: 宋体;" lang="ZH-CN">如何判断某个组件是否需要安装？</span>
</strong>
<span style="font-family: 宋体;" lang="ZH-CN">很简单，到</span>
<span style="font-family: &quot;Courier New&quot;;">LFS</span>
<span style="font-family: 宋体;" lang="ZH-CN">官方网站参考用户手册：</span>
<span style="font-family: &quot;Courier New&quot;;"><a href="http://www.linuxfromscratch.org/lfs/view/stable/">http://www.linuxfromscratch.org/lfs/view/stable/</a>
</span>
<span style="font-family: 宋体;" lang="ZH-CN">，查看一下该组件包含的</span>
<span style="font-family: &quot;Courier New&quot;;">Installed program</span>
<span style="font-family: 宋体;" lang="ZH-CN">，然后在命令行使用</span>
<span style="font-family: &quot;Courier New&quot;;">which</span>
<span style="font-family: 宋体;" lang="ZH-CN">命令找一下，如果找不到，可以肯定需要安装</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 0.25in;"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal" style="margin-left: 39.75pt; text-indent: -21.75pt;"><!-- [if !supportLists]--><span style="font-family: &quot;Courier New&quot;;"><span>2.<span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;
</span>
</span>
</span>
<!-- [endif]--><strong><span style="font-family: 宋体;" lang="ZH-CN">如何判断某个组件是否需要升级？</span>
</strong>
<span style="font-family: 宋体;" lang="ZH-CN">如果通过上述方法能够找到已安装的组件，但是文件的时间比较久远，而且不支持</span>
<span style="font-family: &quot;Courier New&quot;;">—help</span>
<span style="font-family: 宋体;" lang="ZH-CN">参数查看帮助信息或者</span>
<span style="font-family: &quot;Courier New&quot;;">—version</span>
<span style="font-family: 宋体;" lang="ZH-CN">参数查看版本信息，几乎可以肯定需要升级，因为比较新的</span>
<span style="font-family: &quot;Courier New&quot;;">GNU</span>
<span style="font-family: 宋体;" lang="ZH-CN">程序一般都支持这些参数。如果通过</span>
<span style="font-family: &quot;Courier New&quot;;">--version</span>
<span style="font-family: 宋体;" lang="ZH-CN">显示版本较低，也应该升级</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 0.25in;"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal" style="margin-left: 39.75pt; text-indent: -21.75pt;"><!-- [if !supportLists]--><span style="font-family: &quot;Courier New&quot;;"><span>3.<span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;
</span>
</span>
</span>
<!-- [endif]--><span style="font-family: 宋体;" lang="ZH-CN">上述组件的安装一般都是</span>
<strong><span style="font-family: &quot;Courier New&quot;;">./configure &amp;&amp; make
&amp;&amp; make install</span>
</strong>
<span style="font-family: 宋体;" lang="ZH-CN">三部曲。如果没有</span>
<span style="font-family: &quot;Courier New&quot;;">root</span>
<span style="font-family: 宋体;" lang="ZH-CN">权限，可以使用</span>
<span style="font-family: &quot;Courier New&quot;;">./configure --prefix=/path/to/your/directory</span>
<span style="font-family: 宋体;" lang="ZH-CN">指定合法的安装路径，然后根据需要指定</span>
<strong><span style="font-family: &quot;Courier New&quot;;">PATH</span>
</strong>
<span style="font-family: 宋体;" lang="ZH-CN">和</span>
<strong><span style="font-family: &quot;Courier New&quot;;">SHLIB_PATH</span>
</strong>
<span style="font-family: 宋体;" lang="ZH-CN">环境变量。千万要注意，</span>
<span style="font-family: &quot;Courier New&quot;;">HP-UX</span>
<span style="font-family: 宋体;" lang="ZH-CN">的动态链接库的环境变量是</span>
<span style="font-family: &quot;Courier New&quot;;">SHLIB_PATH</span>
<span style="font-family: 宋体;" lang="ZH-CN">，而不是和</span>
<span style="font-family: &quot;Courier New&quot;;">Linux</span>
<span style="font-family: 宋体;" lang="ZH-CN">下的</span>
<span style="font-family: &quot;Courier New&quot;;">LD_LIBRARY_PATH</span>
</p>
<p class="MsoNormal" style="margin-left: 0.25in;"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal" style="margin-left: 39.75pt; text-indent: -21.75pt;"><!-- [if !supportLists]--><span style="font-family: &quot;Courier New&quot;;"><span>4.<span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;
</span>
</span>
</span>
<!-- [endif]--><span style="font-family: 宋体;" lang="ZH-CN">设置环境变量的时候也要注意，如果系统中已经有旧版本的组件，并且新旧版本不在同一目录，</span>
<strong><span style="font-family: &quot;Courier New&quot;;">export</span>
</strong>
<strong><span style="font-family: 宋体;" lang="ZH-CN">环境变量的时候要把新版本组件所在的</span>
</strong>
<strong><span style="font-family: &quot;Courier New&quot;;">lib</span>
</strong>
<strong><span style="font-family: 宋体;" lang="ZH-CN">目录居前</span>
</strong>
<span style="font-family: 宋体;" lang="ZH-CN">，这样系统才能优先搜索得到</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal" style="margin-left: 39.75pt; text-indent: -21.75pt;"><!-- [if !supportLists]--><span style="font-family: &quot;Courier New&quot;;"><span>5.<span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;
</span>
</span>
</span>
<!-- [endif]--><span style="font-family: &quot;Courier New&quot;;">HP-UX</span>
<span style="font-family: 宋体;" lang="ZH-CN">下编译</span>
<strong><span style="font-family: &quot;Courier New&quot;;">flex-2.5.35</span>
</strong>
<span style="font-family: 宋体;" lang="ZH-CN">时会遇到一个棘手的问题</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;; color: green;">ld: Unsatisfied symbol "rpl_realloc" in file dfa.o</span>
</p>
<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;; color: green;">1 errors.</span>
</p>
<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;; color: green;">collect2: ld returned 1 exit status</span>
</p>
<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: 宋体;" lang="ZH-CN">以</span>
<span style="font-family: &quot;Courier New&quot;;">rpl_realloc</span>
<span style="font-family: 宋体;" lang="ZH-CN">为关键字搜索，发现它出现在</span>
<span style="font-family: &quot;Courier New&quot;;">configure</span>
<span style="font-family: 宋体;" lang="ZH-CN">步骤产生的</span>
<span style="font-family: &quot;Courier New&quot;;">config.h</span>
<span style="font-family: 宋体;" lang="ZH-CN">当中</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;; color: green;">/* Define to rpl_realloc if the replacement function should be
used. */</span>
</p>
<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;; color: green;">#define realloc rpl_realloc</span>
</p>
<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: 宋体;" lang="ZH-CN">看样子，可能是为了避免有些系统没有</span>
<span style="font-family: &quot;Courier New&quot;;">realloc</span>
<span style="font-family: 宋体;" lang="ZH-CN">，而转用</span>
<span style="font-family: &quot;Courier New&quot;;">rpl_realloc</span>
<span style="font-family: 宋体;" lang="ZH-CN">代替。这个</span>
<span style="font-family: &quot;Courier New&quot;;">rpl_realloc</span>
<span style="font-family: 宋体;" lang="ZH-CN">不知是哪个系统的函数，</span>
<span style="font-family: &quot;Courier New&quot;;">HP-UX</span>
<span style="font-family: 宋体;" lang="ZH-CN">应该可以使用</span>
<span style="font-family: &quot;Courier New&quot;;">realloc</span>
<span style="font-family: 宋体;" lang="ZH-CN">这个标准</span>
<span style="font-family: &quot;Courier New&quot;;">C</span>
<span style="font-family: 宋体;" lang="ZH-CN">函数呀！于是，把这一行注释了，重新</span>
<span style="font-family: &quot;Courier New&quot;;">make</span>
<span style="font-family: 宋体;" lang="ZH-CN">就正常了</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 0.25in;"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal" style="margin-left: 39.75pt; text-indent: -21.75pt;"><!-- [if !supportLists]--><span style="font-family: &quot;Courier New&quot;;"><span>6.<span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;
</span>
</span>
</span>
<!-- [endif]--><span style="font-family: &quot;Courier New&quot;;">gSOAP-2.7.17</span>
<span style="font-family: 宋体;" lang="ZH-CN">的编译指定要</span>
<strong><span style="font-family: &quot;Courier New&quot;;">automake-1.10</span>
</strong>
<span style="font-family: 宋体;" lang="ZH-CN">版本，如果像我那样不慎安装了</span>
<span style="font-family: &quot;Courier New&quot;;">automake-1.11</span>
<span style="font-family: 宋体;" lang="ZH-CN">，需要自行在其</span>
<span style="font-family: &quot;Courier New&quot;;">bin</span>
<span style="font-family: 宋体;" lang="ZH-CN">目录创建两个链接，否则</span>
<span style="font-family: &quot;Courier New&quot;;">gSOAP</span>
<span style="font-family: 宋体;" lang="ZH-CN">就是傻到不认帐！</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;; color: green;">aclocal-1.10 -&gt; aclocal-1.11</span>
</p>
<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;; color: green;">automake-1.10 -&gt; automake-1.11</span>
</p>
<p class="MsoNormal" style="margin-left: 0.25in;"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal" style="margin-left: 39.75pt; text-indent: -21.75pt;"><!-- [if !supportLists]--><span style="font-family: &quot;Courier New&quot;;"><span>7.<span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;
</span>
</span>
</span>
<!-- [endif]--><span style="font-family: &quot;Courier New&quot;;">gSOAP</span>
<span style="font-family: 宋体;" lang="ZH-CN">的傻事还不止一件，它只认</span>
<strong><span style="font-family: &quot;Courier New&quot;;">flex</span>
</strong>
<strong><span style="font-family: 宋体;" lang="ZH-CN">的动态库而不认静态库</span>
</strong>
<span style="font-family: 宋体;" lang="ZH-CN">，偏偏</span>
<span style="font-family: &quot;Courier New&quot;;">flex</span>
<span style="font-family: 宋体;" lang="ZH-CN">只安装了静态库。所以，安装</span>
<span style="font-family: &quot;Courier New&quot;;">flex</span>
<span style="font-family: 宋体;" lang="ZH-CN">之后，需要手动编译以生成</span>
<span style="font-family: &quot;Courier New&quot;;">libfl.so</span>
<span style="font-family: 宋体;" lang="ZH-CN">，然后再拷贝到其</span>
<span style="font-family: &quot;Courier New&quot;;">lib</span>
<span style="font-family: 宋体;" lang="ZH-CN">目录。</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 0.5in;"><strong><span style="font-family: &quot;Courier New&quot;; color: blue;">gcc -shared -fPCI -o
libfl.so libmain.o libyywrap.o</span>
</strong>
</p>
<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: 宋体;" lang="ZH-CN">此外，还需要在其</span>
<span style="font-family: &quot;Courier New&quot;;">lib</span>
<span style="font-family: 宋体;" lang="ZH-CN">目录创建两个链接，其中第一个是</span>
<span style="font-family: &quot;Courier New&quot;;">LFS</span>
<span style="font-family: 宋体;" lang="ZH-CN">为保持</span>
<span style="font-family: &quot;Courier New&quot;;">lex</span>
<span style="font-family: 宋体;" lang="ZH-CN">与</span>
<span style="font-family: &quot;Courier New&quot;;">flex</span>
<span style="font-family: 宋体;" lang="ZH-CN">的兼容性而建议的，至于第二个，完全是迁就</span>
<span style="font-family: &quot;Courier New&quot;;">gSOAP</span>
<span style="font-family: 宋体;" lang="ZH-CN">的坏脾气</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;; color: green;">libl.so -&gt; libfl.so</span>
</p>
<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;; color: green;">libl.so.1 -&gt; libl.so</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal"><span style="font-family: 宋体;" lang="ZH-CN">如果上述准备工作全部完毕，那么即可正式编译</span>
<span style="font-family: &quot;Courier New&quot;;">gSOAP</span>
<span style="font-family: 宋体;" lang="ZH-CN">。编译步骤同样是</span>
<span style="font-family: &quot;Courier New&quot;;">./configure &amp;&amp; make &amp;&amp; make
install</span>
<span style="font-family: 宋体;" lang="ZH-CN">，似乎乏善可陈。但是，</span>
<span style="font-family: &quot;Courier New&quot;;">gSOAP-2.7.17</span>
<span style="font-family: 宋体;" lang="ZH-CN">似乎有一个</span>
<span style="font-family: &quot;Courier New&quot;;">bug</span>
<span style="font-family: 宋体;" lang="ZH-CN">，在</span>
<span style="font-family: &quot;Courier New&quot;;">HP-UX</span>
<span style="font-family: 宋体;" lang="ZH-CN">下编译会报错：</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">stdsoap2_cpp.cpp:
In function 'size_t frecv(soap*, char*, size_t)':</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">stdsoap2_cpp.cpp:876:
error: invalid conversion from 'socklen_t*' to 'int*'</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">stdsoap2_cpp.cpp:876:
error:<span>&nbsp;&nbsp; </span>
initializing argument 6 of 'int
recvfrom(int, void*, int, int, void*, int*)'</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">stdsoap2_cpp.cpp:
In function 'int tcp_connect(soap*, const char*, const char*, int)':</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">&#8230;&#8230;</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal"><span style="font-family: 宋体;" lang="ZH-CN">一大堆错误信息，其实是指向同一个错误：</span>
<strong><span style="font-family: &quot;Courier New&quot;;">invalid
conversion from 'socklen_t*' to 'int*'</span>
</strong>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal"><span style="font-family: 宋体;" lang="ZH-CN">首先，使用</span>
<span style="font-family: &quot;Courier New&quot;;">find</span>
<span style="font-family: 宋体;" lang="ZH-CN">命令查找</span>
<span style="font-family: &quot;Courier New&quot;;">stdsoap2_cpp.cpp</span>
<span style="font-family: 宋体;" lang="ZH-CN">只有一个</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&gt; <strong><span style="color: blue;">find . -name
"stdsoap2_cpp.cpp"</span>
</strong>
</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">./gsoap/stdsoap2_cpp.cpp</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal"><span style="font-family: 宋体;" lang="ZH-CN">然后，根据错误信息，查看该源程序的</span>
<span style="font-family: &quot;Courier New&quot;;">876</span>
<span style="font-family: 宋体;" lang="ZH-CN">行附近，函数的第六个参数，也就是最后一个参数</span>
<span style="font-family: &quot;Courier New&quot;;">k</span>
<span style="font-family: 宋体;" lang="ZH-CN">是</span>
<span style="font-family: &quot;Courier New&quot;;">SOAP_SOCKLEN_T</span>
<span style="font-family: 宋体;" lang="ZH-CN">类型的</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal"><span style="font-family: 宋体;" lang="ZH-CN">接着，查找所有的头文件，看看该类型是哪个文件定义的</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&gt; <strong><span style="color: blue;">find . -name
"*.h" | xargs grep -l SOAP_SOCKLEN_T</span>
</strong>
</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">./gsoap/samples/calc_vs2005/calc_vs2005/stdsoap2.h</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">./gsoap/samples/wsse/stdsoap2.h</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">./gsoap/stdsoap2.h</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">./gsoap/VisualStudio2005/wsdl2h/wsdl2h/stdsoap2.h</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal"><span style="font-family: 宋体;" lang="ZH-CN">很明显，就在</span>
<span style="font-family: &quot;Courier New&quot;;">./gsoap/stdsoap2.h</span>
<span style="font-family: 宋体;" lang="ZH-CN">中。</span>
<span style="font-family: &quot;Courier New&quot;;">Vi</span>
<span style="font-family: 宋体;" lang="ZH-CN">之，在</span>
<span style="font-family: &quot;Courier New&quot;;">709</span>
<span style="font-family: 宋体;" lang="ZH-CN">行开始其定义：</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;"><span>&nbsp;&nbsp; </span>
<span style="color: green;">709<span>&nbsp; </span>
/* Portability: define SOAP_SOCKLEN_T */</span>
</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;"><span>&nbsp;&nbsp; </span>
710<span>&nbsp;
</span>
#if defined(_AIX)</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;"><span>&nbsp;&nbsp; </span>
711<span>&nbsp; </span>
#
if defined(_AIX43)</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;"><span>&nbsp;&nbsp; </span>
712<span>&nbsp;
</span>
#<span>&nbsp; </span>
define SOAP_SOCKLEN_T socklen_t</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;"><span>&nbsp;&nbsp; </span>
713<span>&nbsp; </span>
#
else</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;"><span>&nbsp;&nbsp; </span>
714<span>&nbsp;
</span>
#<span>&nbsp; </span>
define SOAP_SOCKLEN_T int</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;"><span>&nbsp;&nbsp; </span>
715<span>&nbsp; </span>
#
endif</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;"><span>&nbsp;&nbsp; </span>
716<span>&nbsp;
</span>
#elif defined(SOCKLEN_T)</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;"><span>&nbsp;&nbsp; </span>
717<span>&nbsp; </span>
#
define SOAP_SOCKLEN_T SOCKLEN_T</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;"><span>&nbsp;&nbsp; </span>
718<span>&nbsp;
</span>
#elif defined(__socklen_t_defined) || defined(_SOCKLEN_T) ||
defined(CYGWIN) || defined(FREEBSD) || defined(__FreeBSD__) || defined(OPENBSD)
|| define</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">d(__QNX__)
|| defined(QNX) || defined(OS390) <strong>||
defined(HP_UX)</strong>
</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;"><span>&nbsp;&nbsp; </span>
719<span>&nbsp; </span>
<strong># define SOAP_SOCKLEN_T socklen_t</strong>
</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;"><span>&nbsp;&nbsp; </span>
720<span>&nbsp;
</span>
#elif defined(IRIX) || defined(WIN32) || defined(__APPLE__) ||
defined(SUN_OS) || defined(OPENSERVER) || defined(TRU64) || defined(VXWORKS)</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;"><span>&nbsp;&nbsp; </span>
721<span>&nbsp; </span>
#
define SOAP_SOCKLEN_T int</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;"><span>&nbsp;&nbsp; </span>
722<span>&nbsp;
</span>
#else</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;"><span>&nbsp;&nbsp; </span>
723<span>&nbsp; </span>
#
define SOAP_SOCKLEN_T size_t</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;"><span>&nbsp;&nbsp; </span>
724<span>&nbsp;
</span>
#endif</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal"><span style="font-family: 宋体;" lang="ZH-CN">注意</span>
<span style="font-family: &quot;Courier New&quot;;">718</span>
<span style="font-family: 宋体;" lang="ZH-CN">和</span>
<span style="font-family: &quot;Courier New&quot;;">719</span>
<span style="font-family: 宋体;" lang="ZH-CN">行，</span>
<span style="font-family: &quot;Courier New&quot;;">gSOAP-2.7.17</span>
<span style="font-family: 宋体;" lang="ZH-CN">在</span>
<span style="font-family: &quot;Courier New&quot;;">HP-UX</span>
<span style="font-family: 宋体;" lang="ZH-CN">下，把</span>
<span style="font-family: &quot;Courier New&quot;;">SOAP_SOCKLEN_T</span>
<span style="font-family: 宋体;" lang="ZH-CN">定义为</span>
<span style="font-family: &quot;Courier New&quot;;">socklen_t</span>
<span style="font-family: 宋体;" lang="ZH-CN">，而其它操作系统不是定义为</span>
<span style="font-family: &quot;Courier New&quot;;">int</span>
<span style="font-family: 宋体;" lang="ZH-CN">就定义为</span>
<span style="font-family: &quot;Courier New&quot;;">size_t</span>
<span style="font-family: 宋体;" lang="ZH-CN">，再联系之前的错误信息</span>
<span style="font-family: &quot;Courier New&quot;;">invalid conversion from 'socklen_t*' to
'int*'</span>
<span style="font-family: 宋体;" lang="ZH-CN">，很清楚了，只要在</span>
<span style="font-family: &quot;Courier New&quot;;">719</span>
<span style="font-family: 宋体;" lang="ZH-CN">行把</span>
<span style="font-family: &quot;Courier New&quot;;">socklen_t</span>
<span style="font-family: 宋体;" lang="ZH-CN">改为</span>
<span style="font-family: &quot;Courier New&quot;;">int</span>
<span style="font-family: 宋体;" lang="ZH-CN">就肯定能够在</span>
<span style="font-family: &quot;Courier New&quot;;">HP-UX</span>
<span style="font-family: 宋体;" lang="ZH-CN">下编译通过了。或者严谨一些，把</span>
<span style="font-family: &quot;Courier New&quot;;">718</span>
<span style="font-family: 宋体;" lang="ZH-CN">行的</span>
<span style="font-family: &quot;Courier New&quot;;">defined(HP_UX)</span>
<span style="font-family: 宋体;" lang="ZH-CN">移到</span>
<span style="font-family: &quot;Courier New&quot;;">720</span>
<span style="font-family: 宋体;" lang="ZH-CN">行最后也可以。</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal"><span style="font-family: 宋体;" lang="ZH-CN">上面的问题解决了，继续编译工作，很可能会遇上另一个问题</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">/usr/lib/hpux32/dld.so:
Unsatisfied data symbol 'yylsp' in load module '/usr/lib/hpux32/libl.so.1'.</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">/usr/lib/hpux32/dld.so:
Unsatisfied data symbol 'yyolsp' in load module '/usr/lib/hpux32/libl.so.1'.</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">/usr/lib/hpux32/dld.so:
Unsatisfied data symbol 'yyfnd' in load module '/usr/lib/hpux32/libl.so.1'.</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">&#8230;&#8230;</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal"><span style="font-family: 宋体;" lang="ZH-CN">这是由于系统原来就装有</span>
<span style="font-family: &quot;Courier New&quot;;">flex</span>
<span style="font-family: 宋体;" lang="ZH-CN">，但不是最新版本，结果系统搜索到旧版本的</span>
<span style="font-family: &quot;Courier New&quot;;">libl.so.1</span>
<span style="font-family: 宋体;" lang="ZH-CN">而搜索不到新版本</span>
<span style="font-family: &quot;Courier New&quot;;">libl.so.1</span>
<span style="font-family: 宋体;" lang="ZH-CN">，这就是为什么我在前面要特别强调，</span>
<span style="font-family: &quot;Courier New&quot;;">export</span>
<span style="font-family: 宋体;" lang="ZH-CN">环境变量的时候，要确保新版本所在的路径在前面，并且要在</span>
<span style="font-family: &quot;Courier New&quot;;">flex</span>
<span style="font-family: 宋体;" lang="ZH-CN">的</span>
<span style="font-family: &quot;Courier New&quot;;">lib</span>
<span style="font-family: 宋体;" lang="ZH-CN">目录建立两个链接的原因。</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal"><span style="font-family: 宋体;" lang="ZH-CN">按照上述步骤和错误处理方法，在</span>
<span style="font-family: &quot;Courier New&quot;;">HP-UX</span>
<span style="font-family: 宋体;" lang="ZH-CN">下编译</span>
<span style="font-family: &quot;Courier New&quot;;">gSOAP</span>
<span style="font-family: 宋体;" lang="ZH-CN">应该是不成问题的，推而广之，在其它</span>
<span style="font-family: &quot;Courier New&quot;;">Unix</span>
<span style="font-family: 宋体;" lang="ZH-CN">下编译</span>
<span style="font-family: &quot;Courier New&quot;;">gSOAP</span>
<span style="font-family: 宋体;" lang="ZH-CN">也应该差不多。</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal"><span style="font-family: 宋体;" lang="ZH-CN">最后一个小问题是，在</span>
<span style="font-family: &quot;Courier New&quot;;">HP-UX</span>
<span style="font-family: 宋体;" lang="ZH-CN">下要使用刚刚编译出来的</span>
<span style="font-family: &quot;Courier New&quot;;">soapcpp2</span>
<span style="font-family: 宋体;" lang="ZH-CN">生成存根程序，而不要使用前四节在</span>
<span style="font-family: &quot;Courier New&quot;;">linux</span>
<span style="font-family: 宋体;" lang="ZH-CN">目录下的</span>
<span style="font-family: &quot;Courier New&quot;;">soapcpp2</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&gt; <strong><span style="color: blue;">../../src/soapcpp2
-C -L -x stock.h</span>
</strong>
</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal"><span style="font-family: 宋体;" lang="ZH-CN">更进一步，如果在</span>
<span style="font-family: &quot;Courier New&quot;;">HP-UX</span>
<span style="font-family: 宋体;" lang="ZH-CN">下，需要用到</span>
<span style="font-family: &quot;Courier New&quot;;">libxml2</span>
<span style="font-family: 宋体;" lang="ZH-CN">解析</span>
<span style="font-family: &quot;Courier New&quot;;">SOAP</span>
<span style="font-family: 宋体;" lang="ZH-CN">响应消息，除了编译源代码之外，也可以直接到下列网址下载基于</span>
<span style="font-family: &quot;Courier New&quot;;">HP-UX</span>
<span style="font-family: 宋体;" lang="ZH-CN">的二进制包：</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;"><a href="http://hpux.connect.org.uk/hppd/hpux/Gnome/libxml2-2.7.7/">http://hpux.connect.org.uk/hppd/hpux/Gnome/libxml2-2.7.7/</a>
</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal"><span style="font-family: 宋体;" lang="ZH-CN">这个地址提供了几种版本的二进制包，下载之前应该在命令行输入</span>
<span style="font-family: &quot;Courier New&quot;;">uname &#8211;a</span>
<span style="font-family: 宋体;" lang="ZH-CN">查看一下当前的操作系统信息：</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&gt; <strong><span style="color: blue;">uname -a</span>
</strong>
</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green;">HP-UX hostname
</span>
<span style="font-family: &quot;Courier New&quot;; color: red;">B.11.23</span>
<span style="font-family: &quot;Courier New&quot;; color: green;"> U </span>
<span style="font-family: &quot;Courier New&quot;; color: red;">ia64</span>
<span style="font-family: &quot;Courier New&quot;; color: green;"> 0850816723 unlimited-user license</span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<p class="MsoNormal"><span style="font-family: 宋体;" lang="ZH-CN">根据以上信息，应当下载</span>
<span style="font-family: &quot;Courier New&quot;;">Operating System</span>
<span style="font-family: 宋体;" lang="ZH-CN">为</span>
<span style="font-family: &quot;Courier New&quot;;">HP-UX 11i v2(HP-UX 11.23)</span>
<span style="font-family: 宋体;" lang="ZH-CN">，</span>
<span style="font-family: &quot;Courier New&quot;;">Architecture</span>
<span style="font-family: 宋体;" lang="ZH-CN">为</span>
<span style="font-family: &quot;Courier New&quot;;">Itanium 2</span>
<span style="font-family: 宋体;" lang="ZH-CN">的二进制包</span>
<span style="font-family: &quot;Courier New&quot;;"></span>
</p>
<p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;">&nbsp;</span>
</p>
<span style="font-family: 宋体;" lang="ZH-CN">下载的包是</span>
<span style="font-family: &quot;Courier New&quot;;">libxml2-2.7.7-ia64-11.23.depot.gz</span>
<span style="font-family: 宋体;" lang="ZH-CN">。把它解压后，有</span>
<span style="font-family: &quot;Courier New&quot;;">root</span>
<span style="font-family: 宋体;" lang="ZH-CN">权限的可以使用</span>
<span style="font-family: &quot;Courier New&quot;;">HP-UX</span>
<span style="font-family: 宋体;" lang="ZH-CN">专门的包管理工具安装。没有</span>
<span style="font-family: &quot;Courier New&quot;;">root</span>
<span style="font-family: 宋体;" lang="ZH-CN">权限也不要紧，</span>
<span style="font-family: &quot;Courier New&quot;;">depot</span>
<span style="font-family: 宋体;" lang="ZH-CN">其实就是一个</span>
<span style="font-family: &quot;Courier New&quot;;">tar</span>
<span style="font-family: 宋体;" lang="ZH-CN">包，可以直接使用</span>
<span style="font-family: &quot;Courier New&quot;;">tar</span>
<span style="font-family: 宋体;" lang="ZH-CN">解包，把解包后的文件移动到合适的目录，再设置好</span>
<span style="font-family: &quot;Courier New&quot;;">PATH</span>
<span style="font-family: 宋体;" lang="ZH-CN">和</span>
<span style="font-family: &quot;Courier New&quot;;">SHLIB_PATH</span>
<span style="font-family: 宋体;" lang="ZH-CN">环境变量即可。<br><br><a href="http://blog.csdn.net/yui/archive/2010/08/09/5799465.aspx">http://blog.csdn.net/yui/archive/2010/08/09/5799465.aspx</a><br></span>  <img src ="http://www.cppblog.com/yui/aggbug/125840.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yui/" target="_blank">roy</a> 2010-09-03 23:02 <a href="http://www.cppblog.com/yui/archive/2010/09/03/125840.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用gSOAP开发实例(5) libxml2解析SOAP响应消息</title><link>http://www.cppblog.com/yui/archive/2010/08/30/125287.html</link><dc:creator>roy</dc:creator><author>roy</author><pubDate>Mon, 30 Aug 2010 09:12:00 GMT</pubDate><guid>http://www.cppblog.com/yui/archive/2010/08/30/125287.html</guid><wfw:comment>http://www.cppblog.com/yui/comments/125287.html</wfw:comment><comments>http://www.cppblog.com/yui/archive/2010/08/30/125287.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yui/comments/commentRss/125287.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yui/services/trackbacks/125287.html</trackback:ping><description><![CDATA[<p>电信provisioning系统中，常常需要与远程服务器实时交换一些数据，以完成用户的请求。由于简单对象访问协议（Simple Object Access Protocol, SOAP）的流行，许多涉及到第三方的应用，我们一般都比较乐意使用SOAP来开发。不过，由于可能涉及到公司的机密，本系列教程的开发实例尽量采用在网上已经公开的Web Service资源。</p>
<p>&nbsp;</p>
<p>前面四节的教程，分别采用了股票信息和天气预报的例子。而这两个实例有一个共同点，SOAP响应消息的数据结构相对简单，只需要按拟定的次序，事先约定返回数据代表的意义，就能够实现无歧义的沟通。这就使得gSOAP能够以字符串数组的形式，定义返回结果，再加上一个整型变量，指示返回结果的个数。</p>
<p>&nbsp;</p>
<p>查看一下这两个实例的soapStub.h，可以发现，它们的结果集定义正是这样的：</p>
<p>&nbsp;</p>
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;ns1__ArrayOfString<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;__sizestring;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;sequence&nbsp;of&nbsp;elements&nbsp;&lt;string&gt;&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">**</span><span style="color: #0000ff;">string</span><span style="color: #000000;">;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;optional&nbsp;element&nbsp;of&nbsp;type&nbsp;xsd:string&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br>};</span></div>
<p>&nbsp;</p>
<p><br></p>
<p>但是，如果服务端返回的是一个相对复杂的结果集，事情就不那么好办了。例如，一个提供外汇汇率的Web Service，服务端会同时返回日元、瑞郎、英镑、欧元、澳元、加元、港币合计七种货币兑换美元的汇率情报，每种汇率情报又包括货币代码、当前汇率、涨跌幅、买入价、卖出价、时间戳等多个子项。显然，这不是一个线性结构，而是一个树形结构，就不能使用ArrayOfString来表示了。</p>
<p>&nbsp;</p>
<p>这个案例的End point是：</p>
<p><a href="http://webservice.webxml.com.cn/WebServices/ExchangeRateWebService.asmx">http://webservice.webxml.com.cn/WebServices/ExchangeRateWebService.asmx</a></p>
<p>其WSDL是：</p>
<p><a href="http://webservice.webxml.com.cn/WebServices/ExchangeRateWebService.asmx?wsdl">http://webservice.webxml.com.cn/WebServices/ExchangeRateWebService.asmx?wsdl</a></p>
<p>&nbsp;</p>
<p>参考前面四节的内容，快速建立其存根程序，不再累述。</p>
<p>&nbsp;</p>
<p>我们要实现的API是getExchangeRate，在soapStub.h中搜索，可以发现其返回结果集最终的定义是：</p>
<p>&nbsp;</p>
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;_ns1__getExchangeRateResponse_getExchangeRateResult<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">xsd__schema;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">/*</span><span style="color: #008000;">&nbsp;required&nbsp;element&nbsp;of&nbsp;type&nbsp;xsd:schema&nbsp;</span><span style="color: #008000;">*/</span><span style="color: #000000;"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">__any;<br>};</span></div>
<br>
<p>&nbsp;</p>
仅仅是两个字符串！于是，最初版本的外汇汇率客户端程序只能这样写：<span style="text-decoration: underline;"><br><br>
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000;">#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">iconv.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br><br>#include&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">soapH.h</span><span style="color: #000000;">"</span><span style="color: #000000;"><br>#include&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">ExchangeRateWebServiceSoap12.nsmap</span><span style="color: #000000;">"</span><span style="color: #000000;"><br><br></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;conv_charset(</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">dest,&nbsp;</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">src,&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">input,&nbsp;size_t&nbsp;ilen,&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">output,&nbsp;size_t&nbsp;olen)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;iconv_t&nbsp;conv&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;iconv_open(dest,&nbsp;src);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;conv&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;(iconv_t)&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;memset(output,&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">,&nbsp;olen);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;iconv(conv,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">input,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">ilen,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">output,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">olen)&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;iconv_close(conv);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>}<br><br></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;main(</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;argc,&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">**</span><span style="color: #000000;">argv)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;argc&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">2</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">&nbsp;argc&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">3</span><span style="color: #000000;">&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Usage:&nbsp;%s&nbsp;type&nbsp;[end_point]\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;argv[</span><span style="color: #000000;">0</span><span style="color: #000000;">]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">\ttype&nbsp;=&nbsp;A&nbsp;:&nbsp;all&nbsp;rate\n</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">\ttype&nbsp;=&nbsp;B&nbsp;:&nbsp;basic&nbsp;rate\n</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">\ttype&nbsp;=&nbsp;C&nbsp;:&nbsp;cross&nbsp;rate\n</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;soap&nbsp;soap;<br>&nbsp;&nbsp;&nbsp;&nbsp;soap_init(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">&nbsp;don't&nbsp;set&nbsp;is&nbsp;OK<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">soap_set_mode(&amp;soap,&nbsp;SOAP_C_UTFSTRING);</span><span style="color: #008000;"><br></span><span style="color: #000000;"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;_ns1__getExchangeRate&nbsp;request;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;_ns1__getExchangeRateResponse&nbsp;response;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;request.theType&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;argv[</span><span style="color: #000000;">1</span><span style="color: #000000;">];<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">endpoint&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;NULL;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;argc&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">3</span><span style="color: #000000;">&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;endpoint&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;argv[</span><span style="color: #000000;">2</span><span style="color: #000000;">];<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;soap_call___ns3__getExchangeRate(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap,&nbsp;endpoint,&nbsp;NULL,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">request,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">response)&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;SOAP_OK&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%s\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;response.getExchangeRateResult</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">xsd__schema);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">----------\n</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;ilen&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;strlen(response.getExchangeRateResult</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">__any);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;olen&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;ilen&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">2</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">output&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;(</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">)&nbsp;malloc(</span><span style="color: #0000ff;">sizeof</span><span style="color: #000000;">(</span><span style="color: #0000ff;">char</span><span style="color: #000000;">)&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">&nbsp;olen);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conv_charset(</span><span style="color: #000000;">"</span><span style="color: #000000;">GBK</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">UTF-8</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;response.getExchangeRateResult</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">__any,&nbsp;ilen,&nbsp;output,&nbsp;olen);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%s\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;output);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;free(output);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;">&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;soap_print_fault(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap,&nbsp;stderr);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;soap_destroy(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;soap_end(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;soap_done(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>}</span></div>
<br></span><textarea style="display: none;" cols="50" rows="15" name="code" class="cpp">#include &lt;iconv.h&gt;
#include "soapH.h"
#include "ExchangeRateWebServiceSoap12.nsmap"
int conv_charset(const char *dest, const char *src, char *input, size_t ilen, char *output, size_t olen) {
iconv_t conv = iconv_open(dest, src);
if ( conv == (iconv_t) -1 )
return -1;
memset(output, 0, olen);
if ( iconv(conv, &amp;input, &amp;ilen, &amp;output, &amp;olen) )
return -1;
iconv_close(conv);
return 0;
}
int main(int argc, char **argv) {
if ( argc != 2 &amp;&amp; argc != 3 ) {
printf("Usage: %s type [end_point]\n", argv[0]);
printf("\ttype = A : all rate\n");
printf("\ttype = B : basic rate\n");
printf("\ttype = C : cross rate\n");
exit(-1);
}
struct soap soap;
soap_init(&amp;soap);
// don't set is OK
//soap_set_mode(&amp;soap, SOAP_C_UTFSTRING);
struct _ns1__getExchangeRate request;
struct _ns1__getExchangeRateResponse response;
request.theType = argv[1];
char *endpoint = NULL;
if ( argc == 3 )
endpoint = argv[2];
if ( soap_call___ns3__getExchangeRate(&amp;soap, endpoint, NULL, &amp;request, &amp;response) == SOAP_OK ) {
printf("%s\n", response.getExchangeRateResult-&gt;xsd__schema);
printf("----------\n");
int ilen = strlen(response.getExchangeRateResult-&gt;__any);
int olen = ilen * 2;
char *output = (char *) malloc(sizeof(char) * olen);
conv_charset("GBK", "UTF-8", response.getExchangeRateResult-&gt;__any, ilen, output, olen);
printf("%s\n", output);
free(output);
}
else {
soap_print_fault(&amp;soap, stderr);
}
soap_destroy(&amp;soap);
soap_end(&amp;soap);
soap_done(&amp;soap);
return 0;
}</textarea>
<p>其中，xsd__schema没有中文字符，而__any含有中文字符，需要转换成GBK编码，具体可以参考前面两节。</p>
<p>&nbsp;</p>
<p>编译执行，输出结果如下图：</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><img src="http://hi.csdn.net/attachment/201007/26/0_1280154201f2nH.gif" alt=""></p>
<p>&nbsp;</p>
<p>可以看出，服务端返回的两个长字符串实际上都是基于XML形式的。gSOAP能够自动帮我们完成的也就到此为止，剩下的需要我们自力更生了。</p>
<p>&nbsp;</p>
<p>不过，大家也不用头疼，我们还有另外一个利器——libxml2！网上有很多关于libxml2的教程，所以我也不必多说，只要利用其中几个函数和语句即可。</p>
<p>&nbsp;</p>
<p>1.&nbsp;&nbsp;&nbsp;&nbsp; xmlParseMemory，字符串转为XML文档</p>
<p>2.&nbsp;&nbsp;&nbsp;&nbsp; xmlDocGetRootElement，获取XML文档根节点</p>
<p>3.&nbsp;&nbsp;&nbsp;&nbsp; xmlStrcmp，比较XML字符串，与strcmp差不多</p>
<p>4.&nbsp;&nbsp;&nbsp;&nbsp; curr = curr-&gt;xmlChildrenNode，XML节点指针指向第一个子节点</p>
<p>5.&nbsp;&nbsp;&nbsp;&nbsp; curr = curr-&gt;next，XML节点指针指向下一个兄弟节点</p>
<p>6.&nbsp;&nbsp;&nbsp;&nbsp; xmlNodeGetContent，获取XML节点的内容</p>
<p>7.&nbsp;&nbsp;&nbsp;&nbsp; xmlFreeDoc，释放节点，与free差不多</p>
<p>&nbsp;</p>
<p>最终的外汇汇率客户端程序如下：</p>
<p>&nbsp;
</p>
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000;">#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">iconv.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br>#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">libxml</span><span style="color: #000000;">/</span><span style="color: #000000;">parser.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br>#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">libxml</span><span style="color: #000000;">/</span><span style="color: #000000;">xmlmemory.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br><br>#include&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">soapH.h</span><span style="color: #000000;">"</span><span style="color: #000000;"><br>#include&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">ExchangeRateWebServiceSoap12.nsmap</span><span style="color: #000000;">"</span><span style="color: #000000;"><br><br></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;FIELD_LEN&nbsp;16</span><span style="color: #000000;"><br><br></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;conv_charset(</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">dest,&nbsp;</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">src,&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">input,&nbsp;size_t&nbsp;ilen,&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">output,&nbsp;size_t&nbsp;olen)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;iconv_t&nbsp;conv&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;iconv_open(dest,&nbsp;src);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;conv&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;(iconv_t)&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;memset(output,&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">,&nbsp;olen);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;iconv(conv,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">input,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">ilen,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">output,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">olen)&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;iconv_close(conv);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>}<br><br></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;main(</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;argc,&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">**</span><span style="color: #000000;">argv)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;argc&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">2</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">&nbsp;argc&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">3</span><span style="color: #000000;">&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Usage:&nbsp;%s&nbsp;type&nbsp;[end_point]\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;argv[</span><span style="color: #000000;">0</span><span style="color: #000000;">]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">\ttype&nbsp;=&nbsp;A&nbsp;:&nbsp;all&nbsp;rate\n</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">\ttype&nbsp;=&nbsp;B&nbsp;:&nbsp;basic&nbsp;rate\n</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">\ttype&nbsp;=&nbsp;C&nbsp;:&nbsp;cross&nbsp;rate\n</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;soap&nbsp;soap;<br>&nbsp;&nbsp;&nbsp;&nbsp;soap_init(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">&nbsp;don't&nbsp;set&nbsp;is&nbsp;OK<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">soap_set_mode(&amp;soap,&nbsp;SOAP_C_UTFSTRING);</span><span style="color: #008000;"><br></span><span style="color: #000000;"><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;_ns1__getExchangeRate&nbsp;request;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;_ns1__getExchangeRateResponse&nbsp;response;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;request.theType&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;argv[</span><span style="color: #000000;">1</span><span style="color: #000000;">];<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">endpoint&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;NULL;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;argc&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">3</span><span style="color: #000000;">&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;endpoint&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;argv[</span><span style="color: #000000;">2</span><span style="color: #000000;">];<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;soap_call___ns3__getExchangeRate(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap,&nbsp;endpoint,&nbsp;NULL,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">request,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">response)&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;SOAP_OK&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;len&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;strlen(response.getExchangeRateResult</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">__any);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlDocPtr&nbsp;pdoc&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;xmlParseMemory(response.getExchangeRateResult</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">__any,&nbsp;len);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlNodePtr&nbsp;root&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;xmlDocGetRootElement(pdoc);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlNodePtr&nbsp;curr&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;root;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">&nbsp;(&nbsp;xmlStrcmp(curr</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">name,&nbsp;(</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;xmlChar&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">)&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">getExchangeRate</span><span style="color: #000000;">"</span><span style="color: #000000;">)&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curr&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;curr</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">xmlChildrenNode;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">&nbsp;(&nbsp;curr&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;curr</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">xmlChildrenNode;&nbsp;curr;&nbsp;curr&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;curr</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">next&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlNodePtr&nbsp;data;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">&nbsp;(&nbsp;data&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;curr</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">xmlChildrenNode;&nbsp;data;&nbsp;data&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;data</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">next&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;ifield[FIELD_LEN];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;ofield[FIELD_LEN];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcpy(ifield,&nbsp;xmlNodeGetContent(data));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;conv_charset(</span><span style="color: #000000;">"</span><span style="color: #000000;">GBK</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">UTF-8</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;ifield,&nbsp;strlen(ifield),&nbsp;ofield,&nbsp;FIELD_LEN)&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%s\t%s\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;data</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">name,&nbsp;ifield);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%s\t%s\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;data</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">name,&nbsp;ofield);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">\n</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlFreeDoc(pdoc);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;">&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;soap_print_fault(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap,&nbsp;stderr);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;soap_destroy(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;soap_end(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;soap_done(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>}</span></div>
<p>&nbsp;</p>
<br>
<p>编译时，需要链接libxml2库，同时指定头文件所在路径：</p>
<p><strong>gcc -O2 -o exchange exchange.c soapC.c soapClient.c ../../stdsoap2.c -I../.. -I/usr/include/libxml2 -L../.. -lgsoap -lxml2 </strong></p>
<p><strong>&nbsp;</strong></p>
<p><strong>执行结果（部分）如下：</strong></p>
<p><strong>&nbsp;</strong></p>
<p style="font-family: courier new;"><strong>-bash-3.2$ <strong>./exchange B </strong></strong></p>
<p style="font-family: courier new;"><strong><strong>Code&nbsp;&nbsp;&nbsp; JPY</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>Currency&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 日元</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>ClosePrice&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 87.08</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>DiffPercent&nbsp;&nbsp;&nbsp;&nbsp; -0.29%</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>DiffAmount&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -0.25</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>OpenPrice&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 87.5</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>HighPrice&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 87.71</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>LowPrice&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 87.04</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>Range&nbsp;&nbsp; 0.77%</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>BuyPrice&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 87.08</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>SellPrice&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 87.12</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>ChangeColor&nbsp;&nbsp;&nbsp;&nbsp; Green</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>DataTime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 16:57:54</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>&nbsp;</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>Code</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>CHF</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>Currency&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 瑞郎</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>ClosePrice&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.0552</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>DiffPercent&nbsp;&nbsp;&nbsp;&nbsp; 0.16%</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>DiffAmount&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0.0017</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>OpenPrice&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.054</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>HighPrice&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.0552</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>LowPrice&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.0498</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>Range&nbsp;&nbsp; 0.51%</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>BuyPrice&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.0552</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>SellPrice&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.0556</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>ChangeColor&nbsp;&nbsp;&nbsp;&nbsp; Red</strong></strong></p>
<p style="font-family: courier new;"><strong><strong>DataTime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 16:57:52</strong></strong></p>
<strong><strong>	</strong></strong><br><a  href="http://blog.csdn.net/yui/archive/2010/07/26/5767494.aspx">http://blog.csdn.net/yui/archive/2010/07/26/5767494.aspx</a><br>  <img src ="http://www.cppblog.com/yui/aggbug/125287.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yui/" target="_blank">roy</a> 2010-08-30 17:12 <a href="http://www.cppblog.com/yui/archive/2010/08/30/125287.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用gSOAP开发实例(4) iconv解决中文乱码问题（续）</title><link>http://www.cppblog.com/yui/archive/2010/08/22/124295.html</link><dc:creator>roy</dc:creator><author>roy</author><pubDate>Sun, 22 Aug 2010 10:04:00 GMT</pubDate><guid>http://www.cppblog.com/yui/archive/2010/08/22/124295.html</guid><wfw:comment>http://www.cppblog.com/yui/comments/124295.html</wfw:comment><comments>http://www.cppblog.com/yui/archive/2010/08/22/124295.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yui/comments/commentRss/124295.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yui/services/trackbacks/124295.html</trackback:ping><description><![CDATA[<dl><dt><span style="font-size: small;"><span style="font-family: 宋体;">电信</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US">provisioning</span><span style="font-family: 宋体;">系统中，常常需要与远程服务器实时交换一些数据，以完成用户的请求。由于简单对象访问协议（</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US">Simple Object Access Protocol, SOAP</span><span style="font-family: 宋体;">）的流行，许多涉及到第三方的应用，我们一般都比较乐意使用</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US">SOAP</span><span style="font-family: 宋体;">来开发。不过，由于可能涉及到公司的机密，本系列教程的开发实例尽量采用在网上已经公开的</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US">Web Service</span><span style="font-family: 宋体;">资源。</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US"></span></span></dt><dt><span style="font-family: &quot;courier new&quot;;" lang="EN-US"><span style="font-size: small;">&nbsp;</span></span></dt><dt><span style="font-size: small;"><span style="font-family: 宋体;">上一节，讲解了用</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US">iconv</span><span style="font-family: 宋体;">解决</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US">gSOAP</span><span style="font-family: 宋体;">输出的中文文本乱码的问题。在本节中，我们用一个天气预报客户端的例子，简述一下</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US">gSOAP</span><span style="font-family: 宋体;">输入的中文文本乱码的问题。</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US"></span></span></dt><dt><span style="font-family: &quot;courier new&quot;;" lang="EN-US"><span style="font-size: small;">&nbsp;</span></span></dt><dt><span style="font-size: small;"><span style="font-family: &quot;courier new&quot;;" lang="EN-US">Webxml.com.cn</span><span style="font-family: 宋体;">提供的天气预报</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US">web</span><span style="font-family: 宋体;">服务，</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US">endpoint</span><span style="font-family: 宋体;">地址是：</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US"><a href="http://webservice.webxml.com.cn/WebServices/WeatherWebService.asmx">http://webservice.webxml.com.cn/WebServices/WeatherWebService.asmx</a></span><span style="font-family: 宋体;">，大家可以点击进去，查看一下该服务的所有对外提供的接口。其中，利用</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US">getWeatherbyCityName</span><span style="font-family: 宋体;">接口，可以按给定的城市名字查询该城市的天气预报，如果输入的城市名字不能识别，将统一返回北京的天气预报。</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US"></span></span></dt><dt><span style="font-family: &quot;courier new&quot;;" lang="EN-US"><span style="font-size: small;">&nbsp;</span></span></dt><dt><span style="font-size: small;"><span style="font-family: 宋体;">根据前三节的内容，我们可以很快地准备好其客户端存根程序：</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US"></span></span></dt><dt><strong><span style="color: blue; font-family: &quot;courier new&quot;;" lang="EN-US"><span style="font-size: small;">1.</span><span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span></strong><strong><span style="color: blue; font-family: &quot;courier new&quot;;" lang="EN-US"><span style="font-size: small;">mkdir &#8211;p weather</span></span></strong></dt><dt><strong><span style="color: blue; font-family: &quot;courier new&quot;;" lang="EN-US"><span style="font-size: small;">2.</span><span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span></strong><strong><span style="color: blue; font-family: &quot;courier new&quot;;" lang="EN-US"><span style="font-size: small;">cd weather</span></span></strong></dt><dt><strong><span style="color: blue; font-family: &quot;courier new&quot;;" lang="EN-US"><span style="font-size: small;">3.</span><span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span></strong><strong><span style="color: blue; font-family: &quot;courier new&quot;;" lang="EN-US"><span style="font-size: small;">../wsdl2h -c -o weather.h <br></span></span></strong></dt><dt><strong><span style="color: blue; font-family: &quot;courier new&quot;;" lang="EN-US"><span style="font-size: small;"></span><a href="http://webservice.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl"><span style="font-size: small;">http://webservice.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl</span></a></span></strong></dt><dt><strong><span style="color: blue; font-family: &quot;courier new&quot;;" lang="EN-US"><span style="font-size: small;">4.</span><span style="font: 7pt &quot;Times New Roman&quot;;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span></strong><strong><span style="color: blue; font-family: &quot;courier new&quot;;" lang="EN-US"><span style="font-size: small;">../../bin/linux386/soapcpp2 &#8211;C &#8211;L &#8211;x weather.h</span></span></strong></dt><dt><span style="font-family: &quot;courier new&quot;;" lang="EN-US"><span style="font-size: small;">&nbsp;</span></span></dt><dt><span style="font-size: 12pt; font-family: 宋体;">由于程序并不复杂，直接给出其源代码：</span></dt></dl>
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000;">#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">iconv.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br><br>#include&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">soapH.h</span><span style="color: #000000;">"</span><span style="color: #000000;"><br>#include&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">WeatherWebServiceSoap12.nsmap</span><span style="color: #000000;">"</span><span style="color: #000000;"><br><br></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;OUTPUT_LEN&nbsp;2048</span><span style="color: #000000;"><br><br></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;conv_charset(</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">dest,&nbsp;</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">src,&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">input,&nbsp;size_t&nbsp;ilen,&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">output,&nbsp;size_t&nbsp;olen)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;iconv_t&nbsp;conv&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;iconv_open(dest,&nbsp;src);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;conv&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;(iconv_t)&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;memset(output,&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">,&nbsp;olen);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;iconv(conv,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">input,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">ilen,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">output,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">olen)&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;iconv_close(conv);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>}<br><br></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;main(</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;argc,&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">**</span><span style="color: #000000;">argv)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;argc&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">2</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">&nbsp;argc&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">3</span><span style="color: #000000;">&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Usage:&nbsp;%s&nbsp;city_name&nbsp;[end_point]\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;argv[</span><span style="color: #000000;">0</span><span style="color: #000000;">]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;soap&nbsp;soap;<br>&nbsp;&nbsp;&nbsp;&nbsp;soap_init(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;soap_set_mode(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap,&nbsp;SOAP_C_UTFSTRING);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;_ns1__getWeatherbyCityName&nbsp;request;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;_ns1__getWeatherbyCityNameResponse&nbsp;response;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;size_t&nbsp;ilen&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;strlen(argv[</span><span style="color: #000000;">1</span><span style="color: #000000;">]);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;output[OUTPUT_LEN];<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;conv_charset(</span><span style="color: #000000;">"</span><span style="color: #000000;">UTF-8</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">GBK</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;argv[</span><span style="color: #000000;">1</span><span style="color: #000000;">],&nbsp;ilen,&nbsp;output,&nbsp;OUTPUT_LEN)&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.theCityName&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;argv[</span><span style="color: #000000;">1</span><span style="color: #000000;">];<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.theCityName&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;output;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">endpoint&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;NULL;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;argc&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">3</span><span style="color: #000000;">&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;endpoint&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;argv[</span><span style="color: #000000;">2</span><span style="color: #000000;">];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;soap_call___ns3__getWeatherbyCityName(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap,&nbsp;endpoint,&nbsp;NULL,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">request,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">response)&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;SOAP_OK&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;element_counter&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;response.getWeatherbyCityNameResult</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">__sizestring;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;i&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">&nbsp;(&nbsp;i&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;&nbsp;i&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">&nbsp;element_counter;&nbsp;i</span><span style="color: #000000;">++</span><span style="color: #000000;">&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">switch</span><span style="color: #000000;">&nbsp;(&nbsp;i&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Province&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">1</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">City&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">2</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">City&nbsp;code&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">3</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">City&nbsp;pic.&nbsp;name&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">4</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Timestamp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">5</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Temp.&nbsp;of&nbsp;today&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">6</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Summary&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">7</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Wind&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">8</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Icon&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">9</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Icon&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">10</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Description&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">11</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Reserved&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">12</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Temp.&nbsp;of&nbsp;tomorrow&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">13</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Summary&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">14</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Wind&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">15</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Icon&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">16</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Icon&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">17</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Temp.&nbsp;of&nbsp;af.&nbsp;tmr.&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">18</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Summary&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">19</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Wind&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">20</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Icon&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">21</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Icon&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">22</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Introduction&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">default</span><span style="color: #000000;">&nbsp;:&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ilen&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;strlen(response.getWeatherbyCityNameResult</span><span style="color: #000000;">-&gt;</span><span style="color: #0000ff;">string</span><span style="color: #000000;">[i]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;conv_charset(</span><span style="color: #000000;">"</span><span style="color: #000000;">GBK</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">UTF-8</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;response.getWeatherbyCityNameResult</span><span style="color: #000000;">-&gt;</span><span style="color: #0000ff;">string</span><span style="color: #000000;">[i],&nbsp;ilen,&nbsp;output,&nbsp;OUTPUT_LEN)&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%s\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;response.getWeatherbyCityNameResult</span><span style="color: #000000;">-&gt;</span><span style="color: #0000ff;">string</span><span style="color: #000000;">[i]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%s\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;output);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;">&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;soap_print_fault(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap,&nbsp;stderr);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;soap_destroy(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;soap_end(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;soap_done(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>}</span></div>
<br><dl><dt><br></dt><dt><span style="font-family: 宋体;">编译命令是：</span><strong><span style="color: blue; font-family: &quot;courier new&quot;;" lang="EN-US">gcc -O2 -o weather weather.c soapC.c soapClient.c ../../stdsoap2.c -I../.. -L../.. &#8211;lgsoap</span></strong></dt><dt><span style="font-size: 12pt; font-family: 宋体;">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-family: &quot;courier new&quot;;" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-family: 宋体;">基本上与上一节的股票信息客户端差不多，唯一不同的是，作为输入参数的城市名字，首先需要</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US">iconv</span><span style="font-family: 宋体;">转换编码，从</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US">GBK</span><span style="font-family: 宋体;">转到</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US">UTF-8</span><span style="font-family: 宋体;">，才可以提交给服务端。各位可以试一下，不作转换的话，无论输入什么，服务端只会返回北京的天气预报，因为传入的参数在服务端产生了乱码。</span><span style="font-family: &quot;courier new&quot;;" lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-family: &quot;courier new&quot;;" lang="EN-US">&nbsp;</span></p>
<p><span style="font-size: 12pt; font-family: 宋体;">以下为正常的执行结果，输入广州，可以得到广州的天气预报：</span></p>
</span></dt><dt><span style="font-size: 12pt; font-family: 宋体;"><img src="http://hi.csdn.net/attachment/201007/23/0_12798938319c4e.gif" alt=""></span></dt><dt>
<br></dt><dt><span style="font-size: 12pt; font-family: 宋体;"><span style="font-size: 12pt; font-family: 宋体;">如上图，最后一段的介绍也出现了乱码，不过我认为这是</span><span style="font-size: 12pt; font-family: &quot;courier new&quot;;" lang="EN-US">putty</span><span style="font-size: 12pt; font-family: 宋体;">的问题，行末的最后一个全角字符，如果只能显示一半的话，下一行开始将产生乱码，如果再遇到一个半角字符，又能显示正常了。</span></span></dt><dd><br></dd><dt><a href="http://blog.csdn.net/yui/archive/2010/07/23/5758906.aspx">http://blog.csdn.net/yui/archive/2010/07/23/5758906.aspx</a><br><span style="font-size: 12pt; font-family: 宋体;"><span style="font-size: 12pt; font-family: 宋体;"></span></span></dt></dl> <img src ="http://www.cppblog.com/yui/aggbug/124295.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yui/" target="_blank">roy</a> 2010-08-22 18:04 <a href="http://www.cppblog.com/yui/archive/2010/08/22/124295.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用gSOAP开发实例(3) iconv解决中文乱码问题</title><link>http://www.cppblog.com/yui/archive/2010/08/17/123679.html</link><dc:creator>roy</dc:creator><author>roy</author><pubDate>Tue, 17 Aug 2010 04:01:00 GMT</pubDate><guid>http://www.cppblog.com/yui/archive/2010/08/17/123679.html</guid><wfw:comment>http://www.cppblog.com/yui/comments/123679.html</wfw:comment><comments>http://www.cppblog.com/yui/archive/2010/08/17/123679.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cppblog.com/yui/comments/commentRss/123679.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yui/services/trackbacks/123679.html</trackback:ping><description><![CDATA[<dl style="font-family: courier new;"><dt>电信provisioning系统中，常常需要与远程服务器实时交换一些数据，以完成用户的请求。由于简单对象访问协议（Simple Object Access Protocol, SOAP）的流行，许多涉及到第三方的应用，我们一般都比较乐意使用SOAP来开发。不过，由于可能涉及到公司的机密，本系列教程的开发实例尽量采用在网上已经公开的Web Service资源。</dt><dt>&nbsp;</dt><dt>我开发SOAP应用程序已经有一定的经验，在C/C++环境下一般使用gSOAP，而在Java环境下一般采用axis2。比较两者的话，除了开发语言之外，还是有不少差别，处理中文字符就是其中之一。网上分别搜索一下&#8220;axis2 乱码&#8221;和&#8220;gSOAP 乱码&#8221;，匹配的结果是相差很远的。Axis2好像比较智能，能够识别服务端的字符编码，这方面的问题也少，而最新版本的gSOAP，很可能还是需要程序员做多很多功夫。</dt><dt>&nbsp;</dt><dt>在第一节客户端的教程中，输出的中文股票名称，其实就是乱码，不过为了主次之分，当时做了特别处理，忽略过去。</dt><dt>&nbsp;</dt><dt>网上解决gSOAP乱码的主流方案是，初始化soap对象之后对其设置SOAP_C_UTFSTRING参数，例如：</dt><dt style="color: #0010ff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; struct soap soap;</dt><dt style="color: #0010ff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; soap_init(&amp;soap);</dt><dt style="color: #0010ff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; soap_set_mode(&amp;soap, SOAP_C_UTFSTRING);</dt><dt>&nbsp;</dt><dt>但是，单纯这样修改，在某些特定设置的机器上可能有效，反正我试过，仍然是乱码，如下图。怎么办呢？</dt><dt>&nbsp;</dt><dt><img src="http://hi.csdn.net/attachment/201007/21/0_1279722247dRR2.gif" alt=""></dt><dt>&nbsp;</dt><dt>Linux下有一个字符编码转换的工具iconv，同时也提供了一套可编程的接口。利用它，就可以测试出来自于服务端中文字符编码的类型，从而进一步实现在程序中自动转换编码。</dt><dt>&nbsp;</dt><dt>Iconv常用用法是：<span style="color: #0010ff; font-weight: bold;">iconv -t=to_charset -f=from_charset filename</span></dt><dt>因此，把需要转换编码的内容保存为一个文件，然后执行iconv试出需要转换的编码类型。from&#173;_charset几乎百分百肯定就是utf8，那么to_charset来来去去就那么几个，一个个试也很快试出来了。最终得出的结果是gbk编码，从而修改客户端程序以解决乱码问题。</dt><dt><br></dt></dl>
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000;">#include&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">iconv.h</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br><br>#include&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">soapH.h</span><span style="color: #000000;">"</span><span style="color: #000000;"><br>#include&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">ChinaStockWebServiceSoap12.nsmap</span><span style="color: #000000;">"</span><span style="color: #000000;"><br><br></span><span style="color: #0000ff;">#define</span><span style="color: #000000;">&nbsp;OUTPUT_LEN&nbsp;32</span><span style="color: #000000;"><br><br></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;conv_charset(</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">dest,&nbsp;</span><span style="color: #0000ff;">const</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">src,&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">input,&nbsp;size_t&nbsp;ilen,&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">output,&nbsp;size_t&nbsp;olen)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;iconv_t&nbsp;conv&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;iconv_open(dest,&nbsp;src);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;conv&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;(iconv_t)&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;memset(output,&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">,&nbsp;olen);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;iconv(conv,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">input,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">ilen,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">output,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">olen)&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;iconv_close(conv);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>}<br><br></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;main(</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;argc,&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">**</span><span style="color: #000000;">argv)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;argc&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">2</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">&nbsp;argc&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">3</span><span style="color: #000000;">&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Usage:&nbsp;%s&nbsp;stock_code&nbsp;[end_point]\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;argv[</span><span style="color: #000000;">0</span><span style="color: #000000;">]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;soap&nbsp;soap;<br>&nbsp;&nbsp;&nbsp;&nbsp;soap_init(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;soap_set_mode(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap,&nbsp;SOAP_C_UTFSTRING);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;_ns1__getStockInfoByCode&nbsp;request;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;_ns1__getStockInfoByCodeResponse&nbsp;response;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;request.theStockCode&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;argv[</span><span style="color: #000000;">1</span><span style="color: #000000;">];<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">endpoint&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;NULL;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;argc&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">3</span><span style="color: #000000;">&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;endpoint&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;argv[</span><span style="color: #000000;">2</span><span style="color: #000000;">];<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;soap_call___ns3__getStockInfoByCode(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap,&nbsp;endpoint,&nbsp;NULL,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">request,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">response)&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;SOAP_OK&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;element_counter&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;response.getStockInfoByCodeResult</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">__sizestring;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;i&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">&nbsp;(&nbsp;i&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;&nbsp;i&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">&nbsp;element_counter;&nbsp;i</span><span style="color: #000000;">++</span><span style="color: #000000;">&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">switch</span><span style="color: #000000;">&nbsp;(&nbsp;i&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Stock&nbsp;code&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">1</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Stock&nbsp;name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">2</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Timestamp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">3</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Latest&nbsp;price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">4</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Closing&nbsp;price&nbsp;T-1&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">5</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Opening&nbsp;price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">6</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Ups&nbsp;and&nbsp;downs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">7</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Mininum&nbsp;price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">8</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Maxinum&nbsp;price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">9</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Amount&nbsp;of&nbsp;up/down&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">10</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Trading&nbsp;volume&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">11</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Trading&nbsp;amount&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">12</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Buy&nbsp;price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">13</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Sell&nbsp;price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">14</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Agency&nbsp;trans&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">15</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Buy&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">16</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Buy&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">17</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Buy&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">18</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Buy&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">19</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Buy&nbsp;&nbsp;5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">20</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Sell&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">21</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Sell&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">22</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Sell&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">23</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Sell&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">24</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Sell&nbsp;5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">default</span><span style="color: #000000;">&nbsp;:&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">printf("%s\n",&nbsp;response.getStockInfoByCodeResult-&gt;string[i]);</span><span style="color: #008000;"><br></span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size_t&nbsp;ilen&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;strlen(response.getStockInfoByCodeResult</span><span style="color: #000000;">-&gt;</span><span style="color: #0000ff;">string</span><span style="color: #000000;">[i]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;output[OUTPUT_LEN];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;conv_charset(</span><span style="color: #000000;">"</span><span style="color: #000000;">GBK</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">UTF-8</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;response.getStockInfoByCodeResult</span><span style="color: #000000;">-&gt;</span><span style="color: #0000ff;">string</span><span style="color: #000000;">[i],&nbsp;ilen,&nbsp;output,&nbsp;OUTPUT_LEN)&nbsp;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%s\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;response.getStockInfoByCodeResult</span><span style="color: #000000;">-&gt;</span><span style="color: #0000ff;">string</span><span style="color: #000000;">[i]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%s\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;output);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;">&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;soap_print_fault(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap,&nbsp;stderr);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;soap_destroy(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;soap_end(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;soap_done(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>}</span></div>
<br style="font-family: courier new;"><dl style="font-family: courier new;"><dt>测试成功，如下图：</dt><dt>&nbsp;</dt><dt><br></dt><dt><img src="http://hi.csdn.net/attachment/201007/21/0_1279722281007M.gif" alt=""></dt><dd><br></dd></dl><textarea style="display: none;" cols="50" rows="15" name="code" class="cpp">#include &lt;iconv.h&gt;
#include "soapH.h"
#include "ChinaStockWebServiceSoap12.nsmap"
#define OUTPUT_LEN 32
int conv_charset(const char *dest, const char *src, char *input, size_t ilen, char *output, size_t olen) {
iconv_t conv = iconv_open(dest, src);
if ( conv == (iconv_t) -1 )
return -1;
memset(output, 0, olen);
if ( iconv(conv, &amp;input, &amp;ilen, &amp;output, &amp;olen) )
return -1;
iconv_close(conv);
return 0;
}
int main(int argc, char **argv) {
if ( argc != 2 &amp;&amp; argc != 3 ) {
printf("Usage: %s stock_code [end_point]\n", argv[0]);
exit(-1);
}
struct soap soap;
soap_init(&amp;soap);
soap_set_mode(&amp;soap, SOAP_C_UTFSTRING);
struct _ns1__getStockInfoByCode request;
struct _ns1__getStockInfoByCodeResponse response;
request.theStockCode = argv[1];
char *endpoint = NULL;
if ( argc == 3 )
endpoint = argv[2];
if ( soap_call___ns3__getStockInfoByCode(&amp;soap, endpoint, NULL, &amp;request, &amp;response) == SOAP_OK ) {
int element_counter = response.getStockInfoByCodeResult-&gt;__sizestring;
int i = 0;
for ( i = 0; i &lt; element_counter; i++ ) {
switch ( i ) {
case 0  : printf("Stock code        : "); break;
case 1  : printf("Stock name        : "); break;
case 2  : printf("Timestamp         : "); break;
case 3  : printf("Latest price      : "); break;
case 4  : printf("Closing price T-1 : "); break;
case 5  : printf("Opening price     : "); break;
case 6  : printf("Ups and downs     : "); break;
case 7  : printf("Mininum price     : "); break;
case 8  : printf("Maxinum price     : "); break;
case 9  : printf("Amount of up/down : "); break;
case 10 : printf("Trading volume    : "); break;
case 11 : printf("Trading amount    : "); break;
case 12 : printf("Buy price         : "); break;
case 13 : printf("Sell price        : "); break;
case 14 : printf("Agency trans      : "); break;
case 15 : printf("Buy  1            : "); break;
case 16 : printf("Buy  2            : "); break;
case 17 : printf("Buy  3            : "); break;
case 18 : printf("Buy  4            : "); break;
case 19 : printf("Buy  5            : "); break;
case 20 : printf("Sell 1            : "); break;
case 21 : printf("Sell 2            : "); break;
case 22 : printf("Sell 3            : "); break;
case 23 : printf("Sell 4            : "); break;
case 24 : printf("Sell 5            : "); break;
default : break;
}
//printf("%s\n", response.getStockInfoByCodeResult-&gt;string[i]);
size_t ilen = strlen(response.getStockInfoByCodeResult-&gt;string[i]);
char output[OUTPUT_LEN];
if ( conv_charset("GBK", "UTF-8", response.getStockInfoByCodeResult-&gt;string[i], ilen, output, OUTPUT_LEN) )
printf("%s\n", response.getStockInfoByCodeResult-&gt;string[i]);
else
printf("%s\n", output);
}
}
else {
soap_print_fault(&amp;soap, stderr);
}
soap_destroy(&amp;soap);
soap_end(&amp;soap);
soap_done(&amp;soap);
return 0;
}
</textarea>
<a style="font-family: courier new;"  href="http://blog.csdn.net/yui/archive/2010/07/21/5753879.aspx">http://blog.csdn.net/yui/archive/2010/07/21/5753879.aspx</a>
<br><img src ="http://www.cppblog.com/yui/aggbug/123679.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yui/" target="_blank">roy</a> 2010-08-17 12:01 <a href="http://www.cppblog.com/yui/archive/2010/08/17/123679.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用gSOAP开发实例(2) 股票信息服务端程序</title><link>http://www.cppblog.com/yui/archive/2010/08/14/123468.html</link><dc:creator>roy</dc:creator><author>roy</author><pubDate>Sat, 14 Aug 2010 15:46:00 GMT</pubDate><guid>http://www.cppblog.com/yui/archive/2010/08/14/123468.html</guid><wfw:comment>http://www.cppblog.com/yui/comments/123468.html</wfw:comment><comments>http://www.cppblog.com/yui/archive/2010/08/14/123468.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yui/comments/commentRss/123468.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yui/services/trackbacks/123468.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 电信provisioning系统中，常常需要与远程服务器实时交换一些数据，以完成用户的请求。由于简单对象访问协议（Simple Object Access Protocol, SOAP）的流行，许多涉及到第三方的应用，我们一般都比较乐意使用SOAP来开发。不过，由于可能涉及到公司的机密，本系列教程的开发实例尽量采用在网上已经公开的Web Service资源。&nbsp;上文已经交待了gSOAP在L...&nbsp;&nbsp;<a href='http://www.cppblog.com/yui/archive/2010/08/14/123468.html'>阅读全文</a><img src ="http://www.cppblog.com/yui/aggbug/123468.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yui/" target="_blank">roy</a> 2010-08-14 23:46 <a href="http://www.cppblog.com/yui/archive/2010/08/14/123468.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用gSOAP开发实例(1) 股票信息客户端程序</title><link>http://www.cppblog.com/yui/archive/2010/08/02/121984.html</link><dc:creator>roy</dc:creator><author>roy</author><pubDate>Mon, 02 Aug 2010 09:43:00 GMT</pubDate><guid>http://www.cppblog.com/yui/archive/2010/08/02/121984.html</guid><wfw:comment>http://www.cppblog.com/yui/comments/121984.html</wfw:comment><comments>http://www.cppblog.com/yui/archive/2010/08/02/121984.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.cppblog.com/yui/comments/commentRss/121984.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yui/services/trackbacks/121984.html</trackback:ping><description><![CDATA[<meta http-equiv="Content-Type" content="text/html; charset=" utf-8="">
<meta name="ProgId" content="Word.Document">
<meta name="Generator" content="Microsoft Word 11">
<meta name="Originator" content="Microsoft Word 11"><dl style="font-family: courier new;"><dt>
<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5Croyliang%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C02%5Cclip_filelist.xml"></dt><dt>电信provisioning系统中，常常需要与远程服务器实时交换一些数据，以完成用户的请求。由于简单对象访问协议（Simple
Object Access Protocol, SOAP）的流行，许多涉及到第三方的应用，我们一般都比较乐意使用SOAP来开发。不过，由于可能涉及到公司的机密，本系列教程的开发实例尽量采用在网上已经公开的Web
Service资源。</dt><dt>&nbsp;</dt><dt>gSOAP是一套开源的C/C++软件工具包，使用它能够很方便地开发SOAP网页服务和基于XML的应用程序，就像JAVA里面的axis。</dt><dt>&nbsp;</dt><dt>首先，我们需要从以下地址下载最新版本的gSOAP
2.7.17：</dt><dt><a href="https://sourceforge.net/projects/gsoap2/files/">https://sourceforge.net/projects/gsoap2/files/</a></dt><dt>&nbsp;</dt><dt>其次，gSOAP依赖于Bison和Flex，编译gSOAP的时候会用到，如果没有，从这里下载：</dt><dt>Bison：<a href="http://www.gnu.org/software/bison/">http://www.gnu.org/software/bison/</a></dt><dt>Flex：<a href="http://flex.sourceforge.net/">http://flex.sourceforge.net/</a></dt><dt>&nbsp;</dt><dt>关于这两个工具包的安装步骤可以参考最新的LFS手册： </dt><dt><a href="http://www.linuxfromscratch.org/lfs/view/6.4/chapter06/bison.html">http://www.linuxfromscratch.org/lfs/view/6.4/chapter06/bison.html</a></dt><dt><a href="http://www.linuxfromscratch.org/lfs/view/6.4/chapter06/flex.html">http://www.linuxfromscratch.org/lfs/view/6.4/chapter06/flex.html</a></dt><dt>&nbsp;</dt><dt>如果不是root用户，没有安装权限的话，可以在configure的时候使用--prefix=/path/to/your/own/directory，指定安装路径。装好之后，修改用户目录的.profile文件，更改PATH和LD_LIBRARY_PATH环境变量，使得系统能够正确搜索到你安装后的可执行文件和库文件即可。</dt><dt>&nbsp;</dt><dt>这两步准备工作完成后，我们就可以开始编译gSOAP。Linux下编译安装源代码包无非就是tar zxvf xxx，configure，make，make
install，由于我不是root用户，没有安装的权限，那么不执行make install也可以使用gSOAP开发程序，只不过使用的时候常常需要指定路径。</dt><dt>&nbsp;</dt><dt>现在我们的目标是开发一个获取股票信息的客户端程序。服务端采用webxml开发的WSDL，其URL是：<a href="http://webservice.webxml.com.cn/WebServices/ChinaStockWebService.asmx?wsdl">http://webservice.webxml.com.cn/WebServices/ChinaStockWebService.asmx?wsdl</a></dt><dt>&nbsp;</dt><dt>首先，在gsoap-2.7/gsoap/wsdl/下创建一个stock目录</dt><dt>-bash-3.2$ <strong>mkdir -p stock</strong></dt><dt>&nbsp;</dt><dt>改变当前路径为stock</dt><dt>-bash-3.2$ <strong>cd stock</strong></dt><dt>&nbsp;</dt><dt>使用wsdl2h生成stock.h，如果希望生成纯C代码，需要加上-c参数，否则，将会生成C++代码</dt><dt>-bash-3.2$ <strong>../wsdl2h -c -o
stock.h
http://webservice.webxml.com.cn/WebServices/ChinaStockWebService.asmx?wsdl</strong></dt><dt>&nbsp;</dt><dt style="color: #077c50;">**&nbsp; The gSOAP WSDL/Schema processor for C and
C++, wsdl2h release 1.2.17</dt><dt style="color: #077c50;">**&nbsp; Copyright (C) 2000-2010 Robert van Engelen,
Genivia Inc.</dt><dt style="color: #077c50;">**&nbsp; All Rights Reserved. This product is provided
"as is", without any warranty.</dt><dt style="color: #077c50;">**&nbsp; The wsdl2h tool is released under one of the
following two licenses:</dt><dt style="color: #077c50;">**&nbsp; GPL or the commercial license by Genivia Inc.
Use option -l for more info.</dt><dt style="color: #077c50;">&nbsp;</dt><dt style="color: #077c50;">Saving
stock.h</dt><dt style="color: #077c50;">&nbsp;</dt><dt style="color: #077c50;">Cannot
open file 'typemap.dat'</dt><dt style="color: #077c50;">Problem
reading type map file 'typemap.dat'.</dt><dt style="color: #077c50;">Using
internal type definitions for C instead.</dt><dt style="color: #077c50;">&nbsp;</dt><dt style="color: #077c50;">&nbsp;</dt><dt style="color: #077c50;">Connecting
to 'http://webservice.webxml.com.cn/WebServices/ChinaStockWebService.asmx?wsdl'
to retrieve WSDL/XSD...</dt><dt style="color: #077c50;">Connected,
receiving...</dt><dt style="color: #077c50;">Done
reading
'http://webservice.webxml.com.cn/WebServices/ChinaStockWebService.asmx?wsdl'</dt><dt style="color: #077c50;">&nbsp;</dt><dt style="color: #077c50;">To
complete the process, compile with:</dt><dt style="color: #077c50;">&gt;
soapcpp2 stock.h</dt><dt>&nbsp;</dt><dt>然后，使用soapcpp2生成客户端存根程序和相关的头文件、资源文件，由于我们只开发客户端程序，所以可以指定-C参数</dt><dt>-bash-3.2$ <strong>../../bin/linux386/soapcpp2
-C stock.h</strong></dt><dt>&nbsp;</dt><dt style="color: #077c50;">**&nbsp; The gSOAP code generator for C and C++,
soapcpp2 release 2.7.17</dt><dt style="color: #077c50;">**&nbsp; Copyright (C) 2000-2010, Robert van Engelen,
Genivia Inc.</dt><dt style="color: #077c50;">**&nbsp; All Rights Reserved. This product is provided
"as is", without any warranty.</dt><dt style="color: #077c50;">**&nbsp; The soapcpp2 tool is released under one of
the following three licenses:</dt><dt style="color: #077c50;">**&nbsp; GPL, the gSOAP public license, or the
commercial license by Genivia Inc.</dt><dt style="color: #077c50;">&nbsp;</dt><dt style="color: #077c50;">Saving
soapStub.h annotated copy of the input declarations</dt><dt style="color: #077c50;">Saving
soapH.h interface declarations</dt><dt style="color: #077c50;">Saving
soapC.c XML serializers</dt><dt style="color: #077c50;">Saving
soapClient.c client calling stubs</dt><dt style="color: #077c50;">Saving
soapClientLib.c client stubs with serializers (use only for libs)</dt><dt style="color: #077c50;">Using
ns2 service name: ChinaStockWebServiceSoap</dt><dt style="color: #077c50;">Using
ns2 service style: document</dt><dt style="color: #077c50;">Using
ns2 service encoding: literal</dt><dt style="color: #077c50;">Using
ns2 service location:
http://webservice.webxml.com.cn/WebServices/ChinaStockWebService.asmx</dt><dt style="color: #077c50;">Using
ns2 schema namespace: http://WebXml.com.cn/ChinaStockWebServiceSoap</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap.getStockImageByCode.req.xml sample SOAP/XML request</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap.getStockImageByCode.res.xml sample SOAP/XML response</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap.getStockImageByteByCode.req.xml sample SOAP/XML
request</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap.getStockImageByteByCode.res.xml sample SOAP/XML
response</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap.getStockImage_kByCode.req.xml sample SOAP/XML request</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap.getStockImage_kByCode.res.xml sample SOAP/XML response</dt><dt style="color: #077c50;">Saving ChinaStockWebServiceSoap.getStockImage_kByteByCode.req.xml
sample SOAP/XML request</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap.getStockImage_kByteByCode.res.xml sample SOAP/XML
response</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap.getStockInfoByCode.req.xml sample SOAP/XML request</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap.getStockInfoByCode.res.xml sample SOAP/XML response</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap.nsmap namespace mapping table</dt><dt style="color: #077c50;">Using
ns3 service name: ChinaStockWebServiceSoap12</dt><dt style="color: #077c50;">Using
ns3 service style: document</dt><dt style="color: #077c50;">Using
ns3 service encoding: literal</dt><dt style="color: #077c50;">Using
ns3 service location:
http://webservice.webxml.com.cn/WebServices/ChinaStockWebService.asmx</dt><dt style="color: #077c50;">Using
ns3 schema namespace: http://WebXml.com.cn/ChinaStockWebServiceSoap12</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap12.getStockImageByCode.req.xml sample SOAP/XML request</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap12.getStockImageByCode.res.xml sample SOAP/XML response</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap12.getStockImageByteByCode.req.xml sample SOAP/XML
request</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap12.getStockImageByteByCode.res.xml sample SOAP/XML
response</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap12.getStockImage_kByCode.req.xml sample SOAP/XML
request</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap12.getStockImage_kByCode.res.xml sample SOAP/XML
response</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap12.getStockImage_kByteByCode.req.xml sample SOAP/XML
request</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap12.getStockImage_kByteByCode.res.xml sample SOAP/XML
response</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap12.getStockInfoByCode.req.xml sample SOAP/XML request</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap12.getStockInfoByCode.res.xml sample SOAP/XML response</dt><dt style="color: #077c50;">Saving
ChinaStockWebServiceSoap12.nsmap namespace mapping table</dt><dt style="color: #077c50;">&nbsp;</dt><dt style="color: #077c50;">Compilation
successful</dt><dt>&nbsp;</dt><dt>接着，就可以利用存根程序提供的接口编写客户端程序了，过程相当简单。</dt></dl>
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000;">#include&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">soapH.h</span><span style="color: #000000;">"</span><span style="color: #000000;"><br>#include&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">ChinaStockWebServiceSoap12.nsmap</span><span style="color: #000000;">"</span><span style="color: #000000;"><br><br></span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;main(</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;argc,&nbsp;</span><span style="color: #0000ff;">char</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">**</span><span style="color: #000000;">argv)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;argc&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">2</span><span style="color: #000000;">&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Usage:&nbsp;%s&nbsp;stock_code\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;argv[</span><span style="color: #000000;">0</span><span style="color: #000000;">]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;soap&nbsp;soap;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;soap_init(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;_ns1__getStockInfoByCode&nbsp;request;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">struct</span><span style="color: #000000;">&nbsp;_ns1__getStockInfoByCodeResponse&nbsp;response;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.theStockCode&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;argv[</span><span style="color: #000000;">1</span><span style="color: #000000;">];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;soap_call___ns3__getStockInfoByCode(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap,&nbsp;NULL,&nbsp;NULL,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">request,&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">response)&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;SOAP_OK&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;element_counter&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;response.getStockInfoByCodeResult</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">__sizestring;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;i&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">&nbsp;(&nbsp;i&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;&nbsp;i&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">&nbsp;element_counter;&nbsp;i</span><span style="color: #000000;">++</span><span style="color: #000000;">&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">switch</span><span style="color: #000000;">&nbsp;(&nbsp;i&nbsp;)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Stock&nbsp;code&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">1</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Stock&nbsp;name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">2</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Timestamp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">3</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Latest&nbsp;price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">4</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Closing&nbsp;price&nbsp;T-1&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">5</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Opening&nbsp;price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">6</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Ups&nbsp;and&nbsp;downs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">7</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Mininum&nbsp;price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">8</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Maxinum&nbsp;price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">9</span><span style="color: #000000;">&nbsp;&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Amount&nbsp;of&nbsp;up/down&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">10</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Trading&nbsp;volume&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">11</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Trading&nbsp;amount&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">12</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Buy&nbsp;price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">13</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Sell&nbsp;price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">14</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Agency&nbsp;trans&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">15</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Buy&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">16</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Buy&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">17</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Buy&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">18</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Buy&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">19</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Buy&nbsp;&nbsp;5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">20</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Sell&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">21</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Sell&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">22</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Sell&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">23</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Sell&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">case</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">24</span><span style="color: #000000;">&nbsp;:&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">Sell&nbsp;5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">);&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">default</span><span style="color: #000000;">&nbsp;:&nbsp;</span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">%s\n</span><span style="color: #000000;">"</span><span style="color: #000000;">,&nbsp;response.getStockInfoByCodeResult</span><span style="color: #000000;">-&gt;</span><span style="color: #0000ff;">string</span><span style="color: #000000;">[i]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">else</span><span style="color: #000000;">&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;soap_print_fault(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap,&nbsp;stderr);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;soap_destroy(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;soap_end(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;soap_done(</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">soap);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br>}<br></span></div>
<br><dl style="font-family: courier new;"><dt>
<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5Croyliang%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C03%5Cclip_filelist.xml"></dt><dt>基本上都是套用差不多的格式，不清楚具体参数意义的话，可以参考soapcpp2生成的存根程序及其头文件。把上述代码保存为stock.c，编译命令是：</dt><dt>gcc -O2
-o stock stock.c soapC.c soapClient.c ../../stdsoap2.c -I../.. -L../.. &#8211;lgsoap</dt><dt>&nbsp;</dt><dt>可以看到，编译时，除了stock.c，还需要包括存根程序soapC.c和soapClient.c，以及gSOAP运行时引擎stdsoap2.c，另外还需要指定头文件搜索路径、库文件搜索路径，以及告诉编译器，链接libgsoap</dt><dt>&nbsp;</dt><dt>一切正常的话，就大功告成了：</dt><dt>-bash-3.2$ <strong>./stock sh600000</strong></dt><dt style="color: #077c50;">Stock
code&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : sh600000</dt><dt style="color: #077c50;">Stock
name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 浦发银行</dt><dt style="color: #077c50;">Timestamp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 2010-07-08 15:02:07</dt><dt style="color: #077c50;">Latest
price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 13.79</dt><dt style="color: #077c50;">Closing
price T-1 : 13.76</dt><dt style="color: #077c50;">Opening
price&nbsp;&nbsp;&nbsp;&nbsp; : 13.88</dt><dt style="color: #077c50;">Ups and
downs&nbsp;&nbsp;&nbsp;&nbsp; : 0.03</dt><dt style="color: #077c50;">Mininum
price&nbsp;&nbsp;&nbsp;&nbsp; : 13.73</dt><dt style="color: #077c50;">Maxinum
price&nbsp;&nbsp;&nbsp;&nbsp; : 14.06</dt><dt style="color: #077c50;">Amount of
up/down : 0.22%</dt><dt style="color: #077c50;">Trading
volume&nbsp;&nbsp;&nbsp; : 451017.84</dt><dt style="color: #077c50;">Trading
amount&nbsp;&nbsp;&nbsp; : 62602.5809</dt><dt style="color: #077c50;">Buy
price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 13.78</dt><dt style="color: #077c50;">Sell
price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 13.79</dt><dt style="color: #077c50;">Agency
trans&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 34.07%</dt><dt style="color: #077c50;">Buy&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
: 13.78 / 1622.88</dt><dt style="color: #077c50;">Buy&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
: 13.77 / 687.10</dt><dt style="color: #077c50;">Buy&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
: 13.76 / 785.00</dt><dt style="color: #077c50;">Buy&nbsp; 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
: 13.75 / 1430.00</dt><dt style="color: #077c50;">Buy&nbsp; 5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
: 13.74 / 264.00</dt><dt style="color: #077c50;">Sell
1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 13.79 / 33.70</dt><dt style="color: #077c50;">Sell
2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 13.80 / 64.17</dt><dt style="color: #077c50;">Sell
3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 13.81 / 290.80</dt><dt style="color: #077c50;">Sell
4&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: 13.82 / 1318.70</dt><dt style="color: #077c50;">Sell
5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 13.83 / 647.70</dt></dl>
<p>&nbsp;</p>
<span style="font-family: courier new;"></span><a href="http://blog.csdn.net/yui/archive/2010/07/08/5721877.aspx"><span style="font-family: courier new;">http://blog.csdn.net/yui/archive/2010/07/08/5721877.aspx
</span></a><br>
<meta http-equiv="Content-Type" content="text/html; charset=" utf-8="">
<meta name="ProgId" content="Word.Document">
<meta name="Generator" content="Microsoft Word 11">
<meta name="Originator" content="Microsoft Word 11"><!--[if gte mso 9]><xml>
Normal
0
false
false
false
MicrosoftInternetExplorer4
</xml><![endif]--><!--[if gte mso 9]><xml>
</xml><![endif]--><style>
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
</style><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
<!--[if gte mso 9]><xml>
Normal
0
false
false
false
MicrosoftInternetExplorer4
</xml><![endif]--><!--[if gte mso 9]><xml>
</xml><![endif]--><style>
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;
text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;
text-underline:single;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
</style><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]--> <img src ="http://www.cppblog.com/yui/aggbug/121984.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yui/" target="_blank">roy</a> 2010-08-02 17:43 <a href="http://www.cppblog.com/yui/archive/2010/08/02/121984.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用libz和libbz2的API在项目中集成gzip和bzip2功能</title><link>http://www.cppblog.com/yui/archive/2010/07/30/121684.html</link><dc:creator>roy</dc:creator><author>roy</author><pubDate>Fri, 30 Jul 2010 04:22:00 GMT</pubDate><guid>http://www.cppblog.com/yui/archive/2010/07/30/121684.html</guid><wfw:comment>http://www.cppblog.com/yui/comments/121684.html</wfw:comment><comments>http://www.cppblog.com/yui/archive/2010/07/30/121684.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yui/comments/commentRss/121684.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yui/services/trackbacks/121684.html</trackback:ping><description><![CDATA[<meta http-equiv="Content-Type" content="text/html; charset=" utf-8="">
<meta name="ProgId" content="Word.Document">
<meta name="Generator" content="Microsoft Word 11">
<meta name="Originator" content="Microsoft Word 11">
<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5Croyliang%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"><!--[if gte mso 9]><xml>
Normal
0
false
false
false
MicrosoftInternetExplorer4
</xml><![endif]--><!--[if gte mso 9]><xml>
</xml><![endif]--><style>
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;
text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;
text-underline:single;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.Section1
{page:Section1;}
/* List Definitions */
@list l0
{mso-list-id:1148207972;
mso-list-type:hybrid;
mso-list-template-ids:-1776141254 1452989440 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
{mso-level-tab-stop:39.75pt;
mso-level-number-position:left;
margin-left:39.75pt;
text-indent:-21.75pt;}
@list l1
{mso-list-id:1374498797;
mso-list-type:hybrid;
mso-list-template-ids:-1082648346 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l1:level1
{mso-level-tab-stop:.5in;
mso-level-number-position:left;
text-indent:-.25in;}
ol
{margin-bottom:0in;}
ul
{margin-bottom:0in;}
-->
</style><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
<p>libz提供了一套与gzip有关的API，libbz2提供了一套与bzip2有关的API。我们可以利用其中几个常用的函数，在自己的项目中实现压缩、解压缩功能。这两个库文件一般在linux系统中都会有，如果没有，可以分别到以下网址下载其源代码：</p>
<p>&nbsp;</p>
<p>gzip: <a href="http://www.gzip.org/">http://www.gzip.org/</a></p>
<p>bzip2: <a href="http://www.bzip.org/index.html">http://www.bzip.org/index.html</a></p>
<p>&nbsp;</p>
<p>libz最有用的函数有四个：</p>
<p>&nbsp;</p>
<p>gzFile
gzopen(const char *path, const char *mode);</p>
<p>int
gzclose(gzFile file);</p>
<p>int
gzread(gzFile file, void *buf, unsigned len);</p>
<p>int
gzwrite(gzFile file, const void *buf, unsigned len);</p>
<p>&nbsp;</p>
<p>追踪其源代码的话，可以发现，gzFile也就是void *</p>
<p>&nbsp;</p>
<p>libbz2最有用的函数也有四个：</p>
<p>&nbsp;</p>
<p>BZFILE
*BZ2_bzopen(const char *path, const char *mode);</p>
<p>void
BZ2_bzclose(BZFILE *file);</p>
<p>int
BZ2_bzread(BZFILE *file, void *buf, int len);</p>
<p>int
BZ2_bzwrite(BZFILE *file, void *buf, int len);</p>
<p>&nbsp;</p>
<p>追踪其源代码的话，可以发现，BZFILE也就是void</p>
<p>&nbsp;</p>
<p>所以说，libz的四个函数与libbz2的四个函数，无论从名字上看，还是从参数上看，都是如出一辙的。只不过，gzopen()和gzread()可以打开和读取任何文件，而BZ2_bzopen()和BZ2_bzread()只能打开和读取bzip2压缩的文件。</p>
<p>&nbsp;</p>
<p>事实上，它们与普通文件的打开、关闭、读取、写入的四个函数，基本上是对应的：</p>
<p>&nbsp;</p>
<p>FILE
*fopen(const char *path, const char *mode);</p>
<p>int
fclose(FILE *fp);</p>
<p>int
fread(void *buf, int size_of_element, int len, FILE *fp);</p>
<p>int
fwrite(void *buf, int size_of_element, int len, FILE *fp);</p>
<p>&nbsp;</p>
<p>要打开一个打算读取的二进制文件，三个打开函数的调用分别是：</p>
<p>gzopen("filename",
"r");</p>
<p>BZ2_bzopen("filename",
"r");</p>
<p>fopen("filename",
"rb");</p>
<p>&nbsp;</p>
<p>要打开一个打算写入的二进制文件，三个打开函数的调用分别是：</p>
<p>gzopen("filename",
"w");</p>
<p>BZ2_bzopen("filename",
"w");</p>
<p>fopen("filename",
"w");</p>
<p>&nbsp;</p>
<p>可以说参数的使用是基本一样的，不过gzopen()和BZ2_bzopen()的mode参数一般没有"rb"而只有"r"，因为它们处理的基本上都是二进制文件，不需要特别指明。此外，mode参数还有其它用法，比如制定压缩率等，具体可以查看源代码。</p>
<p>&nbsp;</p>
<p>不同的地方之一，FILE是一个关于文件信息的结构体，而不是void类型，之二，gzread()、gzwrite()、BZ2_bzread()和BZ2_bzwrite()的参数位置与fread()和fwrite()不一样，同时也省略了size_of_element参数。</p>
<p>&nbsp;</p>
<p>有了这两套API，我们就可以很方便地写出程序对文件进行压缩、解压缩操作，更多的是，把压缩、解压缩功能集成到自己的项目中去，使得项目支持压缩格式。举例如下：</p>
<p>&nbsp;</p>
<ol style="margin-top: 0in;" start="1" type="1">
    <li class="MsoNormal">如果使用libz的API，压缩就是对源文件进行fopen()/fread()/fclose()操作，对目标文件进行gzopen()/gzwrite()/gzclose()操作；解压缩就是对源文件进行gzopen()/gzread()/gzclose()操作，对目标文件进行fopen()/fwrite()/fclose()操作</li>
    <li class="MsoNormal">如果使用libbz2的API，压缩就是对源文件进行fopen()/fread()/fclose()操作，对目标文件进行BZ2_bzopen()/BZ2_bzwrite()/BZ2_bzclose()操作；解压缩就是对源文件进行BZ2_bzopen()/BZ2_bzread()/BZ2_bzclose()操作，对目标文件进行fopen()/fwrite()/fclose()操作</li>
</ol>
<p>&nbsp;</p>
<p>如果要直接使用libz和libbz2，很简单，只需要做到三件事：</p>
<p><!--[if !supportLists]-->1.&nbsp;&nbsp;&nbsp;&nbsp;
<!--[endif]-->include头文件。把zlib.h和bzlib.h包含到项目源程序中</p>
<p><!--[if !supportLists]-->2.&nbsp;&nbsp;&nbsp;&nbsp;
<!--[endif]-->链接库文件。如果由于权限问题不能安装库文件，需要在编译时指定库文件的路径</p>
<p><!--[if !supportLists]-->3.&nbsp;&nbsp;&nbsp;&nbsp;
<!--[endif]-->如果库文件没有安装在系统默认的搜索路径，运行前还要修改LD_LIBRARY_PATH环境变量，使得运行时能够找到库文件</p>
<p>&nbsp;</p>
<p>值得注意的是，以上列出的只是libz和libbz2里面最常用、比较高级的函数，其实，这两个库文件里还有其它底层的函数，利用这些底层函数，甚至可以解压.Z结尾的压缩文件。具体做法就要慢慢参透libz的全部源代码了。</p>
<p>&nbsp;</p>
本文来自CSDN博客，转载请标明出处：<a  href="http://blog.csdn.net/yui/archive/2010/07/01/5707842.aspx">http://blog.csdn.net/yui/archive/2010/07/01/5707842.aspx </a><br><br>  <img src ="http://www.cppblog.com/yui/aggbug/121684.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yui/" target="_blank">roy</a> 2010-07-30 12:22 <a href="http://www.cppblog.com/yui/archive/2010/07/30/121684.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用getopt_long()从命令行获取参数</title><link>http://www.cppblog.com/yui/archive/2010/07/29/121617.html</link><dc:creator>roy</dc:creator><author>roy</author><pubDate>Thu, 29 Jul 2010 10:01:00 GMT</pubDate><guid>http://www.cppblog.com/yui/archive/2010/07/29/121617.html</guid><wfw:comment>http://www.cppblog.com/yui/comments/121617.html</wfw:comment><comments>http://www.cppblog.com/yui/archive/2010/07/29/121617.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yui/comments/commentRss/121617.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yui/services/trackbacks/121617.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 众所周知，C程序的主函数有两个参数，其中，第一个参数是整型，可以获得包括程序名字的参数个数，第二个参数是字符数组指针或字符指针的指针，可以按顺序获得命令行上各个字符串参数。其原形是：int main(int argc, char *argv[]);或者int main(int argc, char **argv);&nbsp;如果有一个解析CDR的程序，名叫destroy，负责...&nbsp;&nbsp;<a href='http://www.cppblog.com/yui/archive/2010/07/29/121617.html'>阅读全文</a><img src ="http://www.cppblog.com/yui/aggbug/121617.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yui/" target="_blank">roy</a> 2010-07-29 18:01 <a href="http://www.cppblog.com/yui/archive/2010/07/29/121617.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>strcat在某种特定条件下的优化</title><link>http://www.cppblog.com/yui/archive/2010/07/28/121499.html</link><dc:creator>roy</dc:creator><author>roy</author><pubDate>Wed, 28 Jul 2010 13:46:00 GMT</pubDate><guid>http://www.cppblog.com/yui/archive/2010/07/28/121499.html</guid><wfw:comment>http://www.cppblog.com/yui/comments/121499.html</wfw:comment><comments>http://www.cppblog.com/yui/archive/2010/07/28/121499.html#Feedback</comments><slash:comments>10</slash:comments><wfw:commentRss>http://www.cppblog.com/yui/comments/commentRss/121499.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yui/services/trackbacks/121499.html</trackback:ping><description><![CDATA[<span style="FONT-SIZE: small"><font size=2><span lang=EN-US style="FONT-FAMILY: 宋体">strcat</span><span style="FONT-FAMILY: 宋体">是<span lang=EN-US>C</span>语言一个基本的字符串操作函数，它的源代码一般是这样的。<br><br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">strcat(</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">dest,&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">src)&nbsp;&nbsp;&nbsp;<br><img id=Codehighlighter1_45_167_Open_Image onclick="this.style.display='none'; Codehighlighter1_45_167_Open_Text.style.display='none'; Codehighlighter1_45_167_Closed_Image.style.display='inline'; Codehighlighter1_45_167_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_45_167_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_45_167_Closed_Text.style.display='none'; Codehighlighter1_45_167_Open_Image.style.display='inline'; Codehighlighter1_45_167_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_45_167_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"></span><span id=Codehighlighter1_45_167_Open_Text><span style="COLOR: #000000">{&nbsp;&nbsp;&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">tmp&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;dest;&nbsp;&nbsp;&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">dest)&nbsp;dest</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;&nbsp;&nbsp;&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">&nbsp;((</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">dest</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">src</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">\0</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">);&nbsp;&nbsp;&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;tmp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000">&nbsp;&nbsp;</span></div>
<p></span></font></span><br>由此可见，strcat调用时，先移动目标字符串的指针到其尾部，再进行复制。这种做法对于下标比较大的数组重复调用时，效率比较低。想象一下，第一次调用strcat时，指针由0数到100，只不过复制了几个字符，第二次调用strcat时，指针又从0数到108，无论调用多少次，指针总是从0数起，就会知道这个时候是多么浪费系统资源了！</p>
<p>我找到一个办法，字符串追加时，事先给出目标字符串结尾所在的位置，追加时，也就不用从头开始计算其长度了，复制的过程中，目标字符串的结尾也随之移动，下一次再追加也就可以使用它了。以下就是优化过的string_append，与strcat相比，增加了一个整形指针以传递目标字符串长度的地址。<br><br></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img id=Codehighlighter1_0_77_Open_Image onclick="this.style.display='none'; Codehighlighter1_0_77_Open_Text.style.display='none'; Codehighlighter1_0_77_Closed_Image.style.display='inline'; Codehighlighter1_0_77_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><span id=Codehighlighter1_0_77_Open_Text><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;*&nbsp;optimizer&nbsp;for&nbsp;strcat&nbsp;when&nbsp;appending&nbsp;to&nbsp;a&nbsp;large&nbsp;array&nbsp;again&nbsp;and&nbsp;again<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;</span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br><img id=Codehighlighter1_138_253_Open_Image onclick="this.style.display='none'; Codehighlighter1_138_253_Open_Text.style.display='none'; Codehighlighter1_138_253_Closed_Image.style.display='inline'; Codehighlighter1_138_253_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_138_253_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_138_253_Closed_Text.style.display='none'; Codehighlighter1_138_253_Open_Image.style.display='inline'; Codehighlighter1_138_253_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">string_append(</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">dest,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">end,&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">src)&nbsp;</span><span id=Codehighlighter1_138_253_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"></span><span id=Codehighlighter1_138_253_Open_Text><span style="COLOR: #000000">{<br><img id=Codehighlighter1_173_237_Open_Image onclick="this.style.display='none'; Codehighlighter1_173_237_Open_Text.style.display='none'; Codehighlighter1_173_237_Closed_Image.style.display='inline'; Codehighlighter1_173_237_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_173_237_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_173_237_Closed_Text.style.display='none'; Codehighlighter1_173_237_Open_Image.style.display='inline'; Codehighlighter1_173_237_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">end&nbsp;</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;dest&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;src&nbsp;)&nbsp;</span><span id=Codehighlighter1_173_237_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"></span><span id=Codehighlighter1_173_237_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">p&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;dest&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">end;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">&nbsp;(&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">p</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">src</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)&nbsp;(</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">end)</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;dest;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span></div>
<p><br><span style="FONT-FAMILY: 宋体"><span style="FONT-SIZE: small"><font size=2>经试验，<span lang=EN-US>string_append</span>在大数组重复追加内容的情形下，优势非常明显。其它情形下，使用原来的<span lang=EN-US>strcat</span>也就足够了。<br><br></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">time.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">&nbsp;BUFF_SIZE&nbsp;4096</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img id=Codehighlighter1_82_159_Open_Image onclick="this.style.display='none'; Codehighlighter1_82_159_Open_Text.style.display='none'; Codehighlighter1_82_159_Closed_Image.style.display='inline'; Codehighlighter1_82_159_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top></span><span id=Codehighlighter1_82_159_Open_Text><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;*&nbsp;optimizer&nbsp;for&nbsp;strcat&nbsp;when&nbsp;appending&nbsp;to&nbsp;a&nbsp;large&nbsp;array&nbsp;again&nbsp;and&nbsp;again<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;</span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br><img id=Codehighlighter1_220_335_Open_Image onclick="this.style.display='none'; Codehighlighter1_220_335_Open_Text.style.display='none'; Codehighlighter1_220_335_Closed_Image.style.display='inline'; Codehighlighter1_220_335_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_220_335_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_220_335_Closed_Text.style.display='none'; Codehighlighter1_220_335_Open_Image.style.display='inline'; Codehighlighter1_220_335_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">string_append(</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">dest,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">end,&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">src)&nbsp;</span><span id=Codehighlighter1_220_335_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"></span><span id=Codehighlighter1_220_335_Open_Text><span style="COLOR: #000000">{<br><img id=Codehighlighter1_255_319_Open_Image onclick="this.style.display='none'; Codehighlighter1_255_319_Open_Text.style.display='none'; Codehighlighter1_255_319_Closed_Image.style.display='inline'; Codehighlighter1_255_319_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_255_319_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_255_319_Closed_Text.style.display='none'; Codehighlighter1_255_319_Open_Image.style.display='inline'; Codehighlighter1_255_319_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">end&nbsp;</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;dest&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;src&nbsp;)&nbsp;</span><span id=Codehighlighter1_255_319_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"></span><span id=Codehighlighter1_255_319_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">p&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;dest&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">end;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">&nbsp;(&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">p</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">src</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)&nbsp;(</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">end)</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;dest;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img id=Codehighlighter1_349_1559_Open_Image onclick="this.style.display='none'; Codehighlighter1_349_1559_Open_Text.style.display='none'; Codehighlighter1_349_1559_Closed_Image.style.display='inline'; Codehighlighter1_349_1559_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_349_1559_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_349_1559_Closed_Text.style.display='none'; Codehighlighter1_349_1559_Open_Image.style.display='inline'; Codehighlighter1_349_1559_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()&nbsp;</span><span id=Codehighlighter1_349_1559_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"></span><span id=Codehighlighter1_349_1559_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;j&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;retry&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">100000</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;field&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;output1[BUFF_SIZE],&nbsp;output2[BUFF_SIZE];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;time_t&nbsp;time1&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;time(NULL);<br><img id=Codehighlighter1_514_885_Open_Image onclick="this.style.display='none'; Codehighlighter1_514_885_Open_Text.style.display='none'; Codehighlighter1_514_885_Closed_Image.style.display='inline'; Codehighlighter1_514_885_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_514_885_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_514_885_Closed_Text.style.display='none'; Codehighlighter1_514_885_Open_Image.style.display='inline'; Codehighlighter1_514_885_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(&nbsp;i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;retry;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)&nbsp;</span><span id=Codehighlighter1_514_885_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"></span><span id=Codehighlighter1_514_885_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(output1,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;BUFF_SIZE);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;length&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string_append(output1,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">length,&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">header\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img id=Codehighlighter1_647_833_Open_Image onclick="this.style.display='none'; Codehighlighter1_647_833_Open_Text.style.display='none'; Codehighlighter1_647_833_Closed_Image.style.display='inline'; Codehighlighter1_647_833_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_647_833_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_647_833_Closed_Text.style.display='none'; Codehighlighter1_647_833_Open_Image.style.display='inline'; Codehighlighter1_647_833_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(&nbsp;j&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;j&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;field;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)&nbsp;</span><span id=Codehighlighter1_647_833_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"></span><span id=Codehighlighter1_647_833_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string_append(output1,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">length,&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\tcall&nbsp;detail&nbsp;record&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;c[</span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sprintf(c,&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;j);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string_append(output1,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">length,&nbsp;c);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string_append(output1,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">length,&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string_append(output1,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">length,&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">trailer\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;time_t&nbsp;time2&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;time(NULL);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">It&nbsp;takes&nbsp;%d&nbsp;seconds&nbsp;to&nbsp;show&nbsp;the&nbsp;performance&nbsp;of&nbsp;string_append()\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;time2&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;time1);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;time1&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;time(NULL);<br><img id=Codehighlighter1_1061_1334_Open_Image onclick="this.style.display='none'; Codehighlighter1_1061_1334_Open_Text.style.display='none'; Codehighlighter1_1061_1334_Closed_Image.style.display='inline'; Codehighlighter1_1061_1334_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1061_1334_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1061_1334_Closed_Text.style.display='none'; Codehighlighter1_1061_1334_Open_Image.style.display='inline'; Codehighlighter1_1061_1334_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(&nbsp;i&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;retry;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)&nbsp;</span><span id=Codehighlighter1_1061_1334_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"></span><span id=Codehighlighter1_1061_1334_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(output2,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;BUFF_SIZE);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(output2,&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">header\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img id=Codehighlighter1_1160_1298_Open_Image onclick="this.style.display='none'; Codehighlighter1_1160_1298_Open_Text.style.display='none'; Codehighlighter1_1160_1298_Closed_Image.style.display='inline'; Codehighlighter1_1160_1298_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1160_1298_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1160_1298_Closed_Text.style.display='none'; Codehighlighter1_1160_1298_Open_Image.style.display='inline'; Codehighlighter1_1160_1298_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(&nbsp;j&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;j&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">&nbsp;field;&nbsp;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">&nbsp;)&nbsp;</span><span id=Codehighlighter1_1160_1298_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"></span><span id=Codehighlighter1_1160_1298_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(output2,&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\tcall&nbsp;detail&nbsp;record&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;c[</span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sprintf(c,&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;j);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(output2,&nbsp;c);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(output2,&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(output2,&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">trailer\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;time2&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;time(NULL);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">It&nbsp;takes&nbsp;%d&nbsp;seconds&nbsp;to&nbsp;show&nbsp;the&nbsp;performance&nbsp;of&nbsp;strcat()\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;time2&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">&nbsp;time1);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(&nbsp;strcmp(output1,&nbsp;output2)&nbsp;)<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">They&nbsp;are&nbsp;NOT&nbsp;equal\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">They&nbsp;are&nbsp;equal\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span></div>
<p></font></span></span>&nbsp;</p>
<p><span><span><span><span><span>-bash-3.2$ ./string_append_demo</span></span></span></span></span></p>
<p><span><span><span><span><span>It takes 2 seconds to show the performance of string_append()</span></span></span></span></span></p>
<p><span><span><span><span><span>It takes 11 seconds to show the performance of strcat()</span></span></span></span></span></p>
<p><span><span><span><span><span>They are equal</span></span></span></span></span></p>
<p><br>本文来自CSDN博客，转载请标明出处：<a href="http://blog.csdn.net/yui/archive/2010/05/22/5616455.aspx">http://blog.csdn.net/yui/archive/2010/05/22/5616455.aspx</a></p>
<img src ="http://www.cppblog.com/yui/aggbug/121499.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yui/" target="_blank">roy</a> 2010-07-28 21:46 <a href="http://www.cppblog.com/yui/archive/2010/07/28/121499.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>