完整串
完整串
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| #include<stdlib.h> #define max 255 typedef char sstring[max+1]; void initstring(sstring s1,char *ch) { int i=0; char *p1=s1,*p2=ch; while(*p2!='\0') { i++; *(++p1)=*p2++; } p1++; *p1='\0'; s1[0]=i; } concat(char *s1,char *s2) { char *p1=s1+1,*p2=s2+1; s1[0]=s1[0]+s2[0]; while(*p1) p1++; while(*p1++=*p2++); return *s1; } void main() { sstring s1,s2; initstring(s1,"abcd"); initstring(s2,"efgh"); concat(s1,s2); cout<<s1+1; }
|