Advertisement
Guest User

Untitled

a guest
Jan 24th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int main()
  6. {
  7. FILE *input, *output;
  8. char word[50], *rword, save;
  9. int s = 0,size = 0, e=1;
  10.  
  11. input = fopen("input.txt", "r");
  12.  
  13.  
  14. if (input == NULL)
  15. {
  16. printf("File 'input.txt' does not exist");
  17. fclose(input);
  18. }
  19. else
  20. {
  21. while((fscanf(input, "%c", &word)!=EOF))
  22. {
  23. if(!input) break;
  24. size+=1;
  25. }
  26.  
  27. }
  28. if (size>=50)
  29. {
  30. printf("Invalid input\n");
  31. return 0;
  32. }
  33.  
  34. if (size%2==1)
  35. {
  36. printf("Invalid input\n");
  37. return 0;
  38. }
  39.  
  40. else
  41. for (int i=0; i<size-2/2; i++)
  42. if(word[i]!=word[size-i-1])
  43. e=e-1;
  44.  
  45. printf("e = %d\n",e);
  46. int j=size;
  47. if (e==0)
  48. {
  49. for (int i=0;i<size/2;i++)
  50. {
  51. word[j+1]=*rword+i;
  52. j=j-1;
  53. }
  54. }
  55. else
  56. {
  57. printf("Invalid input\n");
  58. return 0;
  59. }
  60.  
  61.  
  62. for (int i=0;i<size;i++)
  63. printf("%c",word[i]);
  64.  
  65.  
  66. output = fopen("output.txt", "w");
  67. if (output == NULL)
  68. {
  69. printf("File 'output.txt' does not exist");
  70. fclose(output);
  71. }
  72. else
  73. {
  74. for (int i=0;i<size;i++)
  75. fprintf(output,"%c",word[i]);
  76. }
  77. fclose(output);
  78. fclose(input);
  79.  
  80.  
  81. return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement