我写了个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
#include
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...
代码如下:
#include
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已经结束了,后面还能继续添加...
[code]
#include
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...
我基于有人问到strcat函数的问题,就把内核中strcat函数实现的源码等上来,希望那些不知道的同僚们看一下! char * strcat(char * dest, const char * src) { char *tmp = dest; while (*dest) dest++; while ((*dest++ = *src++) != '\0') ; return tmp; }
strcat会导致覆盖,如果操作不慎会导致程序崩溃。以往的做法是先malloc一块新的内存,拷贝一个字符串进取,然后在这个基础上再strcat。感觉还是很容易出错,分配的大小是个问题。不如stl的string来的直接和安全。
例子:(mingwin gcc3.4.2)
#include
#include