- #include <stdio.h>
- #include <string.h>
- void swap(char *a,char *b)
- {
- char temp;
- temp = *a;
- *a = *b;
- *b = temp;
- }
- void change(char *a,char *b,char *c)
- {
- int len_a = strlen(a);
- int len_b = strlen(b);
- int i = 0;
- int j = 0;
- for(i = 0;i < len_b/2;i++) //将b字符串逆向存放
- {
- swap(&b[i],&b[len_b-i-1]);
- }
- if(len_a > len_b) //a字符串比b长的情况
- {
- while(*a)
- {
- while(*b)
- {
- *c = *a;
- c++;
- a++;
- *c = *b;
- c++;
- b++;
- }
- *c = *a;
- c++;
- a++;
- }
- }
- else //b字符串比a长的情况
- {
- while(*b)
- {
- while(*a)
- {
- *c = *a;
- c++;
- a++;
- *c = *b;
- c++;
- b++;
- }
- *c = *b;
- c++;
- b++;
- }
- }
- }
- int main()
- {
- char a[100] = {0};
- char b[100] = {0};
- char c[100] = {0};
- printf("please input string a:\n");
- scanf("%s",a);
- printf("please input string b:\n");
- scanf("%s",b);
- change(a,b,c);
- printf("the result is:%s\n",c);
- return 0;
- }
编写函数void change(char *a,char *b,char*c
最新推荐文章于 2022-05-16 03:09:31 发布