#include <iostream>
#include<bits/stdc++.h>
using namespace std
string FirstAndLast(string str)
{
string ch = str
for (int i = 0
{
int k = i
while (i < ch.length() && ch[i] != ' ')
i++
ch[k] = (char)(ch[k] >= 'a' && ch[k] <= 'z'
? ((int)ch[k] - 32)
: (int)ch[k])
ch[i - 1] = (char)(ch[i - 1] >= 'a' && ch[i - 1] <= 'z'
? ((int)ch[i - 1] - 32)
: (int)ch[i - 1])
}
return ch
}
void insertDemo(string str, string str1)
{
str.insert(12,str1, 0,11)
cout << "After addition of word : "
cout << str
}
int main()
{
char str[200], str1[57], wrd[20]
int i, j, strLen, wrdLen, tmp, chk=0
cout<<"Enter the String: "
gets(str)
cout<<"Enter the Word to delete: "
cin>>wrd
cout << "Enter new word to be added in the middle : "
cin>>str1
cout << "You entered: " << str << endl
cout <<"\n\nCapitalize first and last character :"<< FirstAndLast(str)<<endl
cout << "Original String : " << str << endl
insertDemo(str, str1)
strLen = strlen(str)
wrdLen = strlen(wrd)
for(i=0
{
tmp = i
for(j=0
{
if(str[i]==wrd[j])
i++
}
chk = i-tmp
if(chk==wrdLen)
{
i = tmp
for(j=i
str[j] = str[j+wrdLen]
strLen = strLen-wrdLen
str[j]='\0'
}
}
cout<<"\nNew String after deletion = "<<str<<endl
return 0
}
Comments