C语言:输入一段字符串,要求利用函数覆盖

来源:百度知道 编辑:UC知道 时间:2024/05/28 10:40:08
比如输入字符“12345”,利用函数,使结果为“1122334455”,不知道怎么弄,帮帮忙~~

#include <stdio.h>
#include <conio.h>

char* func(char* dst, const char* src)
{
const char* p = src;
char* q = dst;

do
{
*q++ = *p;
*q++ = *p;
} while (*p++ != 0);

return dst;
}

void main()
{
char buf[256];
printf(func(buf, "12345"));
getch();
}

#include<stdio.h>
#include<string>
void main()
{
char ch[15]="12345";
printf("覆盖之前字符为:%s\n",ch);
strcpy(ch,"1122334455");
printf("覆盖之后字符为:%s\n",ch);
}