C language string reverse splicing

Write a program that allows the user to input an arbitrary string (length less than 50), reverse the string, and splice the original string and the reversed string together (the original string is placed in front, and the reverse order is The string is placed at the end), and the concatenated string is output on the screen.
For example: if the input string: abcde, the output string: abcdeedcba

#include<stdio.h>
#include<string.h> 
int main()
{
    
    
 int len;
 int a,b;
 char str[51];
 char str2[200]; 
 int i=0 ;
printf("输入一个字符串:\n");
 gets(str); 
 len=strlen(str); 
 a=len;
 b=len;
 strcpy(str2,str); 
 while(i<len)
 {
    
    
 str2[a++]=str[--b];
 i++;
 }
str2[a]='\0'; 
 puts(str2); 
return 0; }

Guess you like

Origin blog.csdn.net/weixin_42145554/article/details/129255424