Advertisement
dxvmxnd

kpo_3_16_10

Oct 16th, 2024
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdbool.h>
  4.  
  5. void swapWords(char *str) {
  6. char *words[100];
  7. int count = 0;
  8.  
  9.  
  10. char *token = strtok(str, " ");
  11. while (token != NULL) {
  12. words[count++] = token;
  13. token = strtok(NULL, " ");
  14. }
  15.  
  16.  
  17. for (int i = 0; i < count / 2; i++) {
  18. char *temp = words[i];
  19. words[i] = words[count - i - 1];
  20. words[count - i - 1] = temp;
  21. }
  22.  
  23.  
  24. for (int i = 0; i < count; i++) {
  25. if (i > 0) {
  26. printf(" "); // Добавляем пробелы между словами
  27. }
  28. printf("%s", words[i]);
  29. }
  30. printf("\n");
  31. }
  32.  
  33. int main() {
  34. char str[256];
  35.  
  36. printf("Введите текст:\n");
  37. fgets(str, sizeof(str), stdin);
  38.  
  39.  
  40. str[strcspn(str, "\n")] = '\0';
  41.  
  42. swapWords(str);
  43.  
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement