// 记得多给点分哦,很难写的。
// C
#include
int strnmerge(char*str,int n,char const*s1,char const*s2){
while(n > 0) {
if(!(*s1) && !(*s2)) break;
if(*s1 && n > 0) {
*str++ = *s1++;
--n;
}
if(*s2 && n > 0) {
*str++ = *s2++;
--n;
}
}
*str = '\0';
}
int main() {
char s1[] = "aaaa";
char s2[] = "bbbbbbbbb";
char str[100];
strnmerge(str, 10, s1, s2);
printf("s1 = %s\n", s1);
printf("s2 = %s\n", s2);
printf("str = %s\n", str);
return 0;
}
// C++
#include
using namespace std;
int strnmerge(char*str,int n,char const*s1,char const*s2){
while(n > 0) {
if(!(*s1) && !(*s2)) break;
if(*s1 && n > 0) {
*str++ = *s1++;
--n;
}
if(*s2 && n > 0) {
*str++ = *s2++;
--n;
}
}
*str = '\0';
}
int main() {
char s1[] = "aaaa";
char s2[] = "bbbbbbbbb";
char str[100];
strnmerge(str, 10, s1, s2);
cout << "s1 = " << s1 << endl;
cout << "s2 = " << s2 << endl;
cout << "str = " << str << endl;
return 0;
}
这个适用于哪儿些c语言程序鸭
什么时候要啊 今天就要吗