fork download
  1. //Q96. Reverse each word in a sentence without changing the word order.
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. int main() {
  6. char str[200];
  7. int i, start = 0, end, len;
  8. gets(str);
  9. len = strlen(str);
  10.  
  11. for(i = 0; i <= len; i++) {
  12. if(str[i] == ' ' || str[i] == '\0') {
  13. end = i - 1;
  14. while(start < end) {
  15. char temp = str[start];
  16. str[start] = str[end];
  17. str[end] = temp;
  18. start++;
  19. end--;
  20. }
  21. start = i + 1;
  22. }
  23. }
  24.  
  25. printf("%s", str);
  26. }
  27.  
Success #stdin #stdout 0s 5320KB
stdin
i love coding
stdout
i evol gnidoc