fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int strLength(char *s){
  6. int len = 0;
  7. while(s[len] != '\0') len++;
  8. return len;
  9. }
  10.  
  11.  
  12. char *setPalindrome(char *s){
  13. int len = strLength(s);
  14.  
  15.  
  16. char *p = (char *)malloc(sizeof(char) * (len * 2 + 1));
  17. if(p == NULL){
  18. printf("ERROR\n");
  19. return NULL;
  20. }
  21.  
  22.  
  23. for(int i = 0; i < len; i++){
  24. p[i] = s[i];
  25. }
  26.  
  27.  
  28. for(int i = 0; i < len; i++){
  29. p[len + i] = s[len - 1 - i];
  30. }
  31.  
  32.  
  33. p[len * 2] = '\0';
  34.  
  35. return p;
  36. }
  37.  
  38. int main(void){
  39. char buf[200];
  40. scanf("%s", buf);
  41.  
  42. char *pal = setPalindrome(buf);
  43.  
  44. printf("%s\n", pal);
  45.  
  46. free(pal);
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 5320KB
stdin
nemui
stdout
nemuiiumen