Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void reverse( char *str );
  5.  
  6. int main(void)
  7. {
  8.  
  9. char line[100];
  10. char delim[] = " ";
  11. char *words = NULL;
  12. char *end;
  13.  
  14. int count = 0;
  15.  
  16. printf("Please enter a line of text. Enter new line to complete entry\n");
  17. fgets(line,100,stdin);
  18.  
  19. words = strtok( line, delim );
  20. while ( words != NULL )
  21. {
  22. count++;
  23. words = strtok( NULL, delim );
  24. }
  25.  
  26. *strchr(line, '\n') = '\0';
  27. end = line + strlen(line);
  28.  
  29.  
  30. printf("Number of words in your text: %d\n", count);
  31. printf("\nThe input date encoded:\n");
  32.  
  33. for( ; end > line; end-- )
  34. {
  35.  
  36. if (*end == '\0')
  37. printf("%s\n", end + 1);
  38.  
  39. }
  40.  
  41. printf("\n");
  42.  
  43. return 0;
  44. }
  45.  
  46. void reverse(char *str)
  47. {
  48. char st_letter = str[0], *ptr;
  49.  
  50. for (ptr = str + 1; *ptr; ptr++)
  51. *(ptr - 1) = *ptr;
  52.  
  53. *(ptr - 1) = st_letter;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement