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. // 関数の中でtmpに対してmallocして
  10. // そこに回文を代入してreturnで返しましょう
  11. char *setPalindrome(char s[]){
  12. int len=myStrlen(s);
  13. int total=len*2;
  14.  
  15. char *tmp=(char*)malloc(sizeof(char)*(total+1));
  16.  
  17. if(tmp==NULL){
  18. printf("ERROR\n");
  19. return 0;
  20. }
  21. for(int i=0; i<len; i++){
  22. tmp[i]=s[i];
  23. }
  24. for(int i=0; i<len; i++){
  25. tmp[len+i]=s[len-1-i];
  26. }
  27. return tmp;
  28.  
  29. }
  30.  
  31. int main(){
  32. int i;
  33. char nyuryoku[1024]; //入力
  34. char *kaibun; //回文を受け取る
  35. scanf("%s",nyuryoku);
  36. kaibun = setPalindrome(nyuryoku);
  37. printf("%s\n -> %s\n",nyuryoku,kaibun);
  38. free(kaibun);
  39. return 0;
  40. }
Success #stdin #stdout 0s 5284KB
stdin
abcd
stdout
abcd
  -> abcddcba