Search,insert,swap,delete word from string

Hi all! I am making a program to input a paragraph from the user and then finds/swap/delete/insert a word in that paragraph. I am stuck on the first stage. I have made a program that just returns the starting index of the searched word. But its case sensitive and i want to search case insensitive word. Can someone guide me plz?

#include <iostream>
#include <cstring>
using namespace std;

int main()
{
char str[500],find[500],option;
cout<<"Enter a text paragraph: ";
cin.getline(str,500,'$');
cout<<"\n\t\t String Operations "<<endl;
cout<<"\t Find\t\t:\t\t[F]"<<endl;
cout<<"\t Replace\t:\t\t[R]"<<endl;
cout<<"\t Delete\t\t:\t\t[D]"<<endl;
cout<<"\t Insert\t\t:\t\t[I]"<<endl;
cout<<"\t DeleteSpecial\t:\t\t[S]"<<endl;
cout<<"\t Print\t\t:\t\t[P]"<<endl;
cout<<"\t Quite\t\t:\t\t[Q]"<<endl;
cout<<"\t Enter Option\t:\t";
cin>>option;
cin.ignore(100,'\n');
while (!(option=='F' || option=='f' || option=='R' || option=='r' || option=='D' || option=='d' || option=='I' || option=='i' || option=='S' || option=='s' || option=='P'|| option=='p'|| option=='Q'|| option=='q'))
{
cout<<"\nInvalid option!"<<endl<<endl;
cout<<" Enter One of these Options only"<<endl<<endl;
cout<<"\t Find\t\t:\t\t[F]"<<endl;
cout<<"\t Replace\t:\t\t[R]"<<endl;
cout<<"\t Delete\t\t:\t\t[D]"<<endl;
cout<<"\t Insert\t\t:\t\t[I]"<<endl;
cout<<"\t DeleteSpecial\t:\t\t[S]"<<endl;
cout<<"\t Print\t\t:\t\t[P]"<<endl;
cout<<"\t Quite\t\t:\t\t[Q]"<<endl;
cout<<"\t Enter Option\t:\t";
cin>>option;
cin.ignore(100,'\n');
}
switch(option)
{
case 'F': case 'f':
{
cout<<"Enter the word to find: ";
cin.get(find,100);
cin.ignore(100,'\n');
int wordlen=strlen(find);
for (int i=0;str[i];i++)
{
if (str[i]==find[0])
{
for (int j=0;find[j];j++)
{
if (str[i]==find[j])
{
if ((j+1)==wordlen)
{
cout<<find<<" is found at index "<<(i+1-wordlen)<<endl;
}
i++;
}
}
}
}
}
}
return 0;
}
Please help!
Read: http://www.mochima.com/tutorials/strings.html

Paying special attention to: 'Search Facilities' and 'Erasing and Replacing Substrings'


> But its case sensitive and i want to search case insensitive word.

Make a copy of the string and convert every upper case character in the copy to lower case. Likewise with the word being searched for. Use the copies for finding start indices.
Last edited on
Topic archived. No new replies allowed.