fork download
  1. #include "stdio.h"
  2. #include "locale.h"
  3. #include "stdlib.h"
  4. #include "string.h"
  5.  
  6. void Invert2(char *str, int a, int b)
  7. {
  8. for (int i = 0; i < ((b - a) / 2); i++)
  9. {
  10. char c = str[a + i];
  11. str[a + i] = str[b - 1 - i];
  12. str[b - 1 - i] = c;
  13. }
  14. }
  15.  
  16. void inv(char *str)
  17. {
  18. int dl = strlen(str);
  19. int n = 0;
  20. for (int j = 0; j < dl /* 1000 */; j++)
  21. {
  22. if (str[j] == ' ')
  23. {
  24. Invert2(str, n, j);
  25. n = j+1;
  26. }
  27. }
  28. Invert2(str, 0, dl);
  29. }
  30.  
  31. int main()
  32. {
  33. setlocale(LC_ALL, ".1251");
  34. char *str = malloc(1000);
  35.  
  36. strcpy(str, "123 4567 478 3");
  37. //fgets(str, 1000, stdin);
  38.  
  39. printf("%s\n", str);
  40. inv(str);
  41. printf("%s\n", str);
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 3996KB
stdin
Standard input is empty
stdout
123 4567 478 3
3 478 4567 123