Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <conio.h>
- #include <windows.h>
- using namespace std;
- /*
- int main() {
- char str[81];
- char c;
- cout << "enter your symbol"<<endl;
- cin >> c;
- //fflush(stdin);
- cin.ignore();
- cout << "enter string"<<endl;
- cin.get(str, 81);
- if (str[0] == c)
- {
- int k = 0;
- while (str[k] != ' ')
- {
- cout << str[k];
- k++;
- }
- cout << endl;
- }
- for (int i = 0; str[i] != '\0'; i++)
- {
- if (str[i] == ' ' && str[i + 1] == c)
- {
- i++;
- while (str[i] != ' ' && str[i] != '\0')
- {
- cout << str[i];
- i++;
- }
- i--;
- cout << endl;
- }
- }
- return 0;
- }
- */
- int main() {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- setlocale(LC_ALL, "Russian");
- cout << "Вариант 1 - работа с существующей строкой, иначе - ввод строки самостоятельно"<<endl;
- if (_getch() == '1')
- {
- const char s[20] = "абсдасбдоолалоладл";
- const char ch = 'а';
- const char* p = s;
- const char* p2 = p;
- cout << "Пусть дана строка абсдасбдоолалоладл'. Выведем все символы от а до а" << endl;
- for (; *p2; ++p2)
- if (*p2 == ch && p2 != p)
- {
- cout.write(p, p2 - p) << endl;
- p = p2;
- }
- if (p2 != p)
- cout.write(p, p2 - p) << endl;
- }
- else {
- char s[81];
- char ch;
- cout << "Введите желаемую строку" << endl;
- cin.ignore();
- cin.getline(s, 81);
- cout << "Введите символ,с которого будут начинаться искомые слова"<<endl;
- cin >> ch;
- char* p = s;
- char* p2 = p;
- for (; *p2; ++p2)
- if (*p2 == ch && p2 != p)
- {
- cout.write(p, p2 - p) << endl;
- p = p2;
- }
- if (p2 != p)
- cout.write(p, p2 - p) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement