华为机试—指针合并字符串

来源:互联网 发布:儿童绘画软件哪个好 编辑:程序博客网 时间:2024/05/21 10:04

写一个程序实现功能:将两个字符串合并为一个字符串并且输出,用指针实现。

#include <stdio.h>int main(){    char str1[20]={"Hello "}, str2[20]={"World"};    char *p=str1, *q=str2;    while( *p ) p++;    while( *q )     {        *p = *q;        p++;        q++;    }    *p = '\0';    printf("%s\n", str1);    return 0;}
0 0
原创粉丝点击