rmoronsv

Untitled

Dec 19th, 2019
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. //working
  2. main()
  3. {
  4. int c;
  5. int i = 0;
  6. char array[MAXARRAYSIZE];
  7. while ((c = getchar()) != '!')
  8. array[i++] = c;
  9. array[i] = '\0';
  10. reverse(array);
  11. printf("%s", array);
  12. }
  13. void reverse(char s[])
  14. {
  15. char temp[MAXARRAYSIZE];
  16. int i = 0;
  17. int j = 0;
  18. int pointofreverse = 0;
  19. while (s[i] != '\0' && s[i] != EOF)
  20. {
  21. while (s[i] != '\n' && s[i] != '\0' && s[i] != EOF)
  22. i++;
  23. pointofreverse = i - 1;
  24. while (j < i)
  25. temp[j++] = s[pointofreverse--];
  26. temp[j++] = s[i];
  27. if (s[i] != '\0')
  28. i++;
  29. }
  30. temp[j] = '\0';
  31. i = 0;
  32. while ((s[i] = temp[i]) != '\0')
  33. i++;
  34. }
  35. //not working
  36. main()
  37. {
  38. int c;
  39. int i = 0;
  40. char array[MAXARRAYSIZE];
  41. while ((c = getchar()) != '!')
  42. array[i++] = c;
  43. array[i] = '\0';
  44. reverse(array);
  45. printf("%s", array);
  46. }
  47. void reverse(char s[])
  48. {
  49. char temp[MAXARRAYSIZE];
  50. int i = 0;
  51. int j = 0;
  52. int pointofreverse = 0;
  53. while (s[i] != '\0' && s[i] != EOF)
  54. {
  55. while (s[i] != '\n' && s[i] != '\0' && s[i] != EOF)
  56. i++;
  57. pointofreverse = i - 1;
  58. while (j < i)
  59. temp[j++] = s[pointofreverse--];
  60. temp[j++] = s[i++]; //only difference
  61. }
  62. temp[j] = '\0';
  63. i = 0;
  64. while ((s[i] = temp[i]) != '\0')
  65. i++;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment