Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //удалить предпоследнее слово в строке
- #include <string.h>
- #include <iostream>
- using namespace std;
- int main()
- {
- char str[100];
- char buf[100];
- cout << "Vvedite stroku: ";
- cin.getline(str, 100);
- int j = 0, i;
- for (i = strlen(str)-1; i >= 0; i--)
- {
- if ((j != 0) && (str[i] == ' '))
- break;
- buf[j++] = str[i];
- buf[j] = 0;
- }
- int sled = 0;
- for (; i >= 0; i--)
- {
- if (str[i] != ' ')
- sled = 1;
- if ((str[i] == ' ') && (sled))
- break;
- }
- i++;
- do
- {
- str[i++] = buf[--j];
- } while (buf[j]);
- cout << str << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement