Главная » 2019 » Март » 13 » Удаление слова из предложения
11:04
Удаление слова из предложения

#include <iostream>
using namespace std;
void vvod(char *x);
void vivod(char *x);
int poisk(char *x, char *y);
void cut(char *x, char *y);
int main()
{
    const int n=200;
    char str[n],s[20];
    cout<<"Vvedite stroku: "<<endl; vvod(str);
    cout<<"Vvedite podstroku: "<<endl; vvod(s);
    cut(str,s);
    system("pause");
}
void cut(char *x, char *y)
{
    int i,pos;
    pos=poisk(x,y);
    char newstr[200];
    for (i=0;i<pos;i++) newstr[i]=x[i];
    for (int j=i+strlen(y);j<strlen(x);j++)
        newstr[i++]=x[j];
    newstr[i]='\0';
    vivod(newstr);
}
int poisk(char *x, char *y)
{
    char s[20];
    int i=0,j,pos=-1;
    while (i<strlen(x))
    {
        while ((x[i]==' ')&&(i<strlen(x))) i++;
        j=0;
        while ((x[i]!=' ')&&(i<strlen(x))) 
        {
            s[j++]=x[i++];
        }
        s[j]='\0'; 
        if (!strcmp(s,y))
        {
            pos=i-strlen(s);
            break;
        }
    }
    return pos;
}
void vvod(char *x)
{
    gets(x);
}
void vivod(char *x)
{
    cout<<x<<endl;
}

Просмотров: 264 | Добавил: denjes | Рейтинг: 0.0/0
Всего комментариев: 0
avatar