Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define STR_LEN 80
  4. char str[STR_LEN+1];
  5. void reverse();
  6.  
  7. int main (){
  8. printf ("Enter a sentence: \n");
  9. fgets(str,STR_LEN+1,stdin);
  10.  
  11. puts( str );
  12. reverse();
  13. return 0;
  14. }
  15.  
  16.  
  17. void reverse(){
  18. char newstr[STR_LEN+1];
  19. char thirdar[STR_LEN+1];
  20. char fourar[STR_LEN+1];
  21. char temp[STR_LEN+1];
  22. char output[STR_LEN+1];
  23. char symbol [STR_LEN+1];
  24. int c = 0;
  25. int i;
  26. char ch1;
  27. char ch2;
  28. char ch3;
  29. for(i=0; i<STR_LEN; i++){
  30. ch1 = str[i];
  31. newstr[c] = ch1;
  32. c++;
  33. }
  34. puts( newstr);
  35. int a = strlen(newstr);
  36. a = a - 1;
  37. c=0;
  38. for(i=a;i>-1; i--){
  39. ch2 = newstr[i];
  40. thirdar[c] = ch2;
  41. c++;
  42. }
  43.  
  44. puts( thirdar );
  45.  
  46.  
  47. int b = strlen(thirdar);
  48.  
  49.  
  50. b=b - 1;
  51.  
  52. for(i=b;i>-1;i--){
  53. while(c < b+1){
  54. ch3 = thirdar[i];
  55. if ((ch3 != ' ') ||(ch3 != '?')||(ch3 != '!')||(ch3 != '.')){
  56. fourar[c] = ch3;
  57. fourar[c+1] = '\0';
  58. strcpy(temp, fourar);
  59. c--;
  60. c++;
  61.  
  62.  
  63. }
  64. else if(ch3 == ' '){
  65. fourar[c] = ch3;
  66. fourar[c+1] = '\0';
  67. strcpy(temp, fourar);
  68. c--;
  69. c++;
  70. }
  71. else if((ch3 != '?')||(ch3 != '!')||(ch3 != '.')){
  72. fourar[c] = ch3;
  73. fourar[c+1] = '\0';
  74. strcpy(symbol, fourar);
  75. c--;
  76. c++;
  77. }
  78. }
  79. }
  80. int d = strlen(temp);
  81. int e = strlen(fourar);
  82. if(e == d){
  83. strcat(symbol, fourar);
  84. strcpy(output, symbol);
  85. }
  86. else{
  87. strcat(symbol,fourar);
  88. strcat(symbol, temp);
  89. strcpy(output, symbol);
  90. }
  91. puts( output);
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement