Advertisement
Guest User

d24

a guest
Nov 20th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. /*
  2. Computing I -- COMP.1010 Honor Statement
  3.  
  4. The practice of good ethical behavior is essential for maintaining
  5. good order in the classroom, providing an enriching learning
  6. experience for students, and as training as a practicing computing
  7. professional upon graduation. This practice is manifested in the
  8. University's Academic Integrity policy. Students are expected to
  9. strictly avoid academic dishonesty and adhere to the Academic
  10. Integrity policy as outlined in the course catalog. Violations
  11. will be dealt with as outlined therein.
  12.  
  13. All programming assignments in this class are to be done by the
  14. student alone. No outside help is permitted except the instructor
  15. and approved tutors.
  16.  
  17. I certify that the work submitted with this assignment is mine and
  18. was generated in a manner consistent with this document, the
  19. course academic policy on the course website on Blackboard, and
  20. the UMass Lowell academic code.
  21.  
  22. Date: 11/20/2019
  23. Name: Jensen Packard
  24. */
  25.  
  26. #include <stdio.h>
  27.  
  28. void strInput(char str[], int numch);
  29. void reverseString(char str[], int numch);
  30.  
  31. int main(int argc,char *argv[])
  32. {
  33. int numch = 80;
  34. char str[numch+1];
  35.  
  36. printf("Please enter a string:\n");
  37. strInput(str, numch);
  38.  
  39. reverseString(str, numch);
  40.  
  41.  
  42. return 0;
  43. }
  44.  
  45.  
  46. void strInput(char str[], int numch) {
  47.  
  48. int i = 0;
  49. char in;
  50. while((in = getchar()) != '\n' && i <= (numch-1)) {
  51. str[i] = in;
  52. i++;
  53. }
  54. str[i] = '\0';
  55. printf("%s\n", str);
  56. }
  57.  
  58. void reverseString(char str[], int numch)
  59. {
  60. int count = 0;
  61.  
  62. for(int i = 0; i < 80; i++)
  63. {
  64. if (str[i] == '\0')
  65. {
  66. break;
  67. }
  68.  
  69. ++count;
  70. }
  71.  
  72. for(int x = 0; x < count/2; x++)
  73. {
  74. char hold = str[x];
  75. str[x] = str[count - x - 1];
  76. str[count - x - 1] = hold;
  77. }
  78.  
  79. printf("%s\n", str);
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement