fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int myStrlen(char s[]) {
  5. int i;
  6. for(i = 0; s[i] != '\0'; i++);
  7. return i;
  8. }
  9.  
  10. char *setPalindrome(char s[]) {
  11. int len = myStrlen(s);
  12. int i, total_len;
  13. char *tmp;
  14.  
  15. total_len = 2 * len;
  16. tmp = (char *)malloc((total_len + 1) * sizeof(char));
  17. if (tmp == NULL) {
  18. printf("ERROR\n");
  19. exit(1);
  20. }
  21.  
  22. for (i = 0; i < len; i++) {
  23. tmp[i] = s[i];
  24. }
  25.  
  26. for (i = 0; i < len; i++) {
  27. tmp[len + i] = s[len - i - 1];
  28. }
  29.  
  30. tmp[total_len] = '\0';
  31.  
  32. return tmp;
  33. }
  34.  
  35. int main() {
  36. int i;
  37. char nyuryoku[1024];
  38. char *kaibun;
  39. scanf("%s", nyuryoku);
  40. kaibun = setPalindrome(nyuryoku);
  41. printf("%s\n -> %s\n", nyuryoku, kaibun);
  42. free(kaibun);
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0s 5280KB
stdin
abcd
stdout
abcd
  -> abcddcba