C语言代码和运行结果如下:
输出符合样例,望采纳~
附源码:
#include <stdio.h>
#include <string.h>
void join(char *s1, char *s2) {
char s[100]// 保存拼接结果
int i, j, k = 0
for (i = 0s1[i] != '\0'++i) {
s[k++] = s1[i]// 先复制s1中的1个字符
for (j = 0s2[j] != '\0'++j)
s[k++] = s2[j]// 再拼接整个s2
}
strcpy(s1, s)// 最后再将拼接好的s复制回s1
}
int main() {
char s1[100] = "ABCD"
char s2[100] = "*"
join(s1, s2)
printf("%s\n", s1)
return 0
}
#include "stdafx.h"#include "conio.h"
char *myfun(char *strA, char *strB, char strC)//strA用户数据,strB返回数据, strC插入字符
{
int m = 0
if (strA == NULL)
return NULL
int n = strlen(strA)
for (int i=0i<ni++)
{
strB[m]=strA[i]
if (strA[i]>= 0x30 &&strA[i]<= 0x39 )
{
strB[m+1] = strC
m += 1
}
m += 1
}
strB[m] = '\0'
return strB
}
main()
{
char p[] = "2m1f3d2de4wer5"
int k = strlen(p)
char *buff = (char *)malloc(k*2+1)
char *p1 = myfun(p, buff, 's')
printf("%s\n", p1)
free(buff)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)