Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdbool.h>
- void swapWords(char *str) {
- char *words[100];
- int count = 0;
- char *token = strtok(str, " ");
- while (token != NULL) {
- words[count++] = token;
- token = strtok(NULL, " ");
- }
- for (int i = 0; i < count / 2; i++) {
- char *temp = words[i];
- words[i] = words[count - i - 1];
- words[count - i - 1] = temp;
- }
- for (int i = 0; i < count; i++) {
- if (i > 0) {
- printf(" "); // Добавляем пробелы между словами
- }
- printf("%s", words[i]);
- }
- printf("\n");
- }
- int main() {
- char str[256];
- printf("Введите текст:\n");
- fgets(str, sizeof(str), stdin);
- str[strcspn(str, "\n")] = '\0';
- swapWords(str);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement