ChinaUnix.net
相关文章推荐:

strcat()函数

我写了个strcat()函数 感觉没有问题啊但是m老是循环请高手指点 char* strcat1(char *p,char *q) { char *m=p; while(*m!='/0') { printf("%c",*m); m++; } while(*q!='/0') { *m++=*q++; } return (p); }

by gaozhongshan - C/C++ - 2007-06-07 14:52:49 阅读(1954) 回复(19)

相关讨论

9 #include 10 #include 11 12 char *mystrcat(char *dest, char *source) 13 { 14 char *ptr = dest; 15 if (dest == NULL || source == NULL) { 16 printf("the input string is error!\n"); 17 return NULL; 18 } 19 20 while (*dest++ != '\0') 21 ; 22 dest--; 23 24 while (*dest++ = *source++) 25 ; 26 return ptr...

by phillipls - C/C++ - 2007-10-31 10:53:29 阅读(8031) 回复(17)

#include main() { char *b; char *a="test"; strcat(b,a); printf("%s",b); } 编译后执行报错 Segmentation fault,请问为什么

by xiehc - C/C++ - 2009-04-27 19:08:00 阅读(984) 回复(8)

man strcat有一段话是这样说的: The strcat() function appends the src string to the dest string over- writing the ‘\0’ character at the end of dest, and then adds a termi- nating ‘\0’ character. The strings may not overlap, and the dest string must have enough space for the result. [code] char a[5]="this"; char *b="test"; strcat(a,b); pr...

by xxldc - C/C++ - 2008-04-11 15:49:15 阅读(2108) 回复(12)

代码如下: #include #include main() { char *c="Golden Global"; char *a="jjjjjjjjj"; char *s; s=(char *)malloc(100*sizeof(char)); char *p; p=s; printf("%p\n",s); strcat(s,c); s=s+2; printf("%p\n" ,s); strcat(s,a); printf("%p\n",s); printf("%s\n",p); return 0...

by yuangong - C/C++ - 2006-10-16 12:52:20 阅读(797) 回复(5)

char * __cdecl strcat ( char * dst, const char * src ) { char * cp = dst; while( *cp ) cp++; /* find end of dst */ while( *cp++ = *src++ ) ; /* Copy src to end of dst */ return( dst ); /* return dst */ } 这是一段微软写的strcat函数,现在有个疑问,为什么CP已经结束了,后面还能继续添加...

by wanghu8242837 - C/C++ - 2009-01-13 16:11:10 阅读(2274) 回复(13)

[code] #include #include int main() { char s1[] = "hahaha"; char *s2 = "*******\n"; strcat(s1, s2); printf("S1 bytes = %d\n", sizeof(s1)); printf("s1 = %s", s1); return 0; } [/code] 当s2增加字节数时,为什么会出现段错误?

by xiaozhu2007 - C/C++ - 2008-04-06 11:47:14 阅读(2577) 回复(13)

char *sqlTmp = "select a.vendor_id,h.int_id from mscwbb h,objects a where a.int_id=h.int_id and a.foreign_object_ind=0 and h.spc='"; strcat(strsql,sqlTmp); strcat(strsql,hlr_spc); strcat(strsql,"' and a.confirmed<>2"); 其中strcat(strsql,"' and a.confirmed<>2");,编译器是不是自动分配一个变量,然后赋值' and a.confirmed<>2,然后把这个自动变量带入strcat函数作为第二个参数。我看函数的原型为char *strcat...

by arenxl - C/C++ - 2007-03-14 10:00:32 阅读(1297) 回复(10)

我基于有人问到strcat函数的问题,就把内核中strcat函数实现的源码等上来,希望那些不知道的同僚们看一下! char * strcat(char * dest, const char * src) { char *tmp = dest; while (*dest) dest++; while ((*dest++ = *src++) != '\0') ; return tmp; }

by mike_chen - C/C++ - 2005-05-03 12:08:08 阅读(5105) 回复(6)

strcat会导致覆盖,如果操作不慎会导致程序崩溃。以往的做法是先malloc一块新的内存,拷贝一个字符串进取,然后在这个基础上再strcat。感觉还是很容易出错,分配的大小是个问题。不如stl的string来的直接和安全。 例子:(mingwin gcc3.4.2) #include #include int main(void){ int buf[]={17,3,15,2}; int a=3; char b1[]="abc"; int b=5; char b2[]="xyz"; int c=7; char* b3=strcat(...

by jeanlove - C/C++ - 2009-02-06 11:30:40 阅读(2202) 回复(13)

#include #include using namespace std; void main() { char * str1 = "You "; cout << "str1(before) = " << str1; char * str2 = "are good"; strcat(str1, str2); cout << "str1(after) = " << str2; } 这段程序编译连接可以通过. 执行strcat(st1, str2)句时会报错:" staticunion.exe 遇到问题需要关闭。我们对此引起的不便表示抱歉。" 后面的cout语句没有输出 谁能告诉...

by washen - C/C++ - 2007-11-25 17:16:27 阅读(2765) 回复(2)