本帖最后由 jiangenhao 于 2014-4-26 01:07 编辑
- char * strcpy2 ( char * str1, const char *str2)
- {
- char * cp = str1;
- while (*str1 != '\0')
- {
- * str1 = * str2;
- * str1++;
- * str2++;
-
-
- }
- // *str1 = '\0';
- return cp;
- }
- #include <stdio.h>
- int main(int argc, const char * argv[])
- {
- char a[] = "sahghag";
- char b[] = "welcome to beijing!";
- char * result = strcpy2(a,b);
- // printf("%s\n",result);
- printf("%s\n",a);
- return 0;
- }
复制代码
为什么结果是welcome呢 空格也算'\0'吗
|