字符数组问题
<P>现有3个字符数组: char a[9999],char b[9999],char c[9999],如何把这三个字符数组 合并成一个 char[99999];和 string aa; 高手提点下[em08]</P><P>我也是菜鸟,麻烦你弄个简单的算法![em04]</P> <P>是啊 5楼的有简单的 弄个我门看看啊</P> <P>不知道![em04]<BR>请高手指点![em04]</P> 我觉得用<BR>for(int i=0;i<lenth(a)+lenth(b)+lenth(c);i++)<BR>就可以了。<BR><BR>你写的:<BR>for(int j=0;j<9999;j++)<BR>{<BR> if(a[j]!=null)<BR> {<BR> d[i]=a[j];<BR> i++;<BR> }<BR> else<BR> break;<BR>}<BR>其中if(a[j]!=null),是什么?null代表空,只要a[]这个数组赋值了,就没有空的,这个是多余的,楼主也没说清楚,到底赋值过什么。再有,假如a[100]这个值是空,而a[101]这个值是有值的,你这么写,a[101]的值就丢了,当然这只是假设,因为我可以单独用:a[100]=null; 这个办法赋值。 <P>一行的程序呀。变char[99999]:<BR>#include <stdio.h><BR>#include <string><BR>#include <sstream><BR>using namespace std;</P>
<P>void main()<BR>{<BR>char a[9999], b[9999], c[9999],d[99999];<BR>sprintf(d, "%s%s%s", a,b,c);</P>
<P>stringstream ss;<BR>ss << a << b << c;<BR>string aa = ss.str();<BR>}<BR></P>
页:
[1]
