<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[strstr  substr在截取字符串前面位置的中的用法,分离url里的get参数的键值~]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Fri, 14 Mar 2008 05:26:40 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	#include &lt;fstream&gt;<br/>#include &lt;iostream&gt;<br/>#include &quot;/usr/local/mysql/include/mysql/mysql.h&quot;<br/>const char mysqlServer[20] = &quot;10.88.15.114&quot;;<br/>//const char mysqlServer[20] = &quot;10.88.15.114&quot;;<br/>const char user[20]=&quot;web&quot;;<br/>const char password[20]=&quot;sinatest&quot;;<br/>const char database[20]=&quot;enterprise&quot;;<br/>unsigned&nbsp;&nbsp;int port=3306;<br/>using namespace std;<br/>int main()<br/>&#123;<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;MYSQL myData;<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;MYSQL_RES *res;<br/>&nbsp;&nbsp;MYSQL_FIELD *fd;<br/>&nbsp;&nbsp;MYSQL_ROW row;<br/>&nbsp;&nbsp;int i,j,rowCount = 0,colCount = 0;<br/>&nbsp;&nbsp;string query;<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;mysql_init( &amp;myData );<br/>&nbsp;&nbsp;if(!mysql_real_connect( &amp;myData, mysqlServer, user, password, database,port,NULL,0))<br/>&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;connect mysql error!&#92;n&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;cout &lt;&lt;&quot;the mysql is ok!&#92;n&quot;;<br/>&nbsp;&nbsp;query = &quot;select email from enterprisemail_info where enterpriseid=100334 &quot;;<br/>&nbsp;&nbsp;if( mysql_query(&amp;myData, query.c_str()) != 0 )<br/>&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;printf(&quot;query error!&#92;n&quot;);<br/>&nbsp;&nbsp;cout &lt;&lt; query;<br/>&nbsp;&nbsp;return 0;<br/>&nbsp;&nbsp;&#125;else&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; &quot;mysql query run ok!&#92;n&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp; &#125;<br/>&nbsp;&nbsp;res = mysql_store_result( &amp;myData );<br/>&nbsp;&nbsp;rowCount = (int) mysql_num_rows( res );<br/>&nbsp;&nbsp;colCount = (int) mysql_num_fields( res );<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;//cout &lt;&lt; colCount&lt;&lt;&quot;&#92;t&quot;&lt;&lt;rowCount&lt;&lt;&quot;&#92;n&quot;;<br/>&nbsp;&nbsp;for(i = 0; i &lt; rowCount; i++)<br/>&nbsp;&nbsp;&#123;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;//第一种方法取出@前面的用户名<br/>&nbsp;&nbsp;&nbsp;&nbsp;row = mysql_fetch_row( res );<br/>&nbsp;&nbsp;&nbsp;&nbsp;char buffer[1024],buffer2[1024];<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(buffer,row[0]);&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;char* p = strstr(buffer,&quot;@&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;*p=0;<br/>&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt;&quot;strstr=&quot;&lt;&lt;buffer&lt;&lt;&quot;&#92;t&quot;;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;//第二种方法取出@前面的用户名<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(buffer2,row[0]);<br/>&nbsp;&nbsp;&nbsp;&nbsp;char* p2 = strstr(buffer2,&quot;@&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;int points= p2-buffer2;<br/>&nbsp;&nbsp;&nbsp;&nbsp;string buffer3=buffer2;<br/>&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;&quot;substr=&quot;&lt;&lt;buffer3.substr(0, points)&lt;&lt;endl;<br/><br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/><br/>&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;cout &lt;&lt;&quot;&#92;n&quot;;<br/><br/>&#125;<br/><br/>分离url里的get参数的键值~<br/><textarea name="code" class="php" rows="15" cols="100">
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
int main()&#123;
&nbsp;&nbsp;&nbsp;&nbsp;char * query_string = &quot;para1=val1&amp;para2=val2&amp;para3=val3&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;char * str = (char *)malloc(strlen(query_string)+1);
&nbsp;&nbsp;&nbsp;&nbsp;char * index;
&nbsp;&nbsp;&nbsp;&nbsp;memcpy(str, query_string, strlen(query_string)+1);
&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;&nbsp;i=0,m;
&nbsp;&nbsp;&nbsp;&nbsp;char * get[100];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp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sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//printf(&quot;%s&#92;n&quot;, index);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;get[i] = (char *)malloc(index-str + 1);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strncpy(get[i++], str, index - str);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strncpy(str, index + 1, strlen(str)-(index-str) + 1);
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;get[i] = (char*)malloc(strlen(str)+1);
&nbsp;&nbsp;&nbsp;&nbsp;strncpy(get[i++], str, strlen(str)+1);
&nbsp;&nbsp;&nbsp;&nbsp;for(m=0; m&lt;i; m++)&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;%s&#92;n&quot;, get[m]);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;free(get[m]);
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&#125;
</textarea><br/><br/>[root@test geturi]# gcc geturi.c <br/>[root@test geturi]# ./a.out <br/>para1=val1<br/>para2=val2<br/>para3=val3<br/><br/>________________________________________________________________<br/>头文件：#include &lt;string.h&gt;<br/>strchr() 用来查找某字符在字符串中首次出现的位置，其原型为：<br/>char * strchr (const char *str, int c);<br/>【参数】str 为要查找的字符串，c 为要查找的字符。<br/>strchr() 将会找出 str 字符串中第一次出现的字符 c 的地址，然后将该地址返回。<br/>摘自：http://c.biancheng.net/cpp/html/161.html<br/><br/>strchr与strstr函数，strchr函数的语法格式怎么用？它的作用与strstr函数有什么区别？<br/>在C语言中 strchr 和 strstr函数都被包含在&lt;string.h&gt;头文件中，也就是要调用它们时要在程序前面包含&lt;string.h&gt;头文件，也就是写这个语句：#include&lt;string.h&gt;<br/>strchr函数原型：char * strchr(char * str, int ch); 功能就是找出在字符串str中第一次出项字符ch的位置，找到就返回该字符位置的指针(也就是返回该字符在字符串中的地址的位置)，找不到就返回空指针(就是 null)。<br/>strstr 函数原型： char * strstr(char * str1,char * str2);功能就是找出在字符串str1中第一次出项字符串str2的位置(也就是说字符串sr1中要包含有字符串str2)，找到就返回该字符串位置的指针(也就是返回字符串str2在字符串str1中的地址的位置)，找不到就返回空指针(就是 null)。<br/><br/>它们一个是求一个字符在字符串中得位置，另一个是求一个字符串在另一个字符串中的位置。<br/>这些在C语言书最后面中都有的，你要学会去多看看书，要会自己解决问题。学编程是要有耐心的，学久了就会懂了。<br/>来自：http://zhidao.baidu.com/link?url=sANNu-OqOB2bmhvJuBEOC1n7S8oeuSOoBcx47GsH0UcScIr3uMFXiZsQNtTu1MNkJGnHuTtCjrBrNdDEcLy2eq
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] strstr  substr在截取字符串前面位置的中的用法,分离url里的get参数的键值~]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>