fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(void) {
  5. char sentence[100];
  6. char *words[50];
  7. int count = 0;
  8.  
  9. printf("Enter a line of text: ");
  10. fgets(sentence, sizeof(sentence), stdin);
  11. sentence[strcspn(sentence, "\n")] = '\0';
  12.  
  13. char *token = strtok(sentence, " ");
  14. while (token != NULL && count < 50) {
  15. words[count++] = token;
  16. token = strtok(NULL, " ");
  17. }
  18.  
  19. printf("Reversed words: ");
  20. for (int i = count - 1; i >= 0; i--) {
  21. printf("%s ", words[i]);
  22. }
  23. printf("\n");
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
Enter a line of text: Reversed words: