remove first character from string

hi everyone i need some help i have this program in this i have two strings string s and string t. and after taking input from user i compare that string t contained in string s or not if it contained then its ok but if the first character of string t is not contained in string s then i have to remove the first character of string t and then again compare it anyone can tell me that how i will do that easily.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <string>
using namespace std;

int main()
{
char *ptr, str1[80], str2[80];

/* Input the strings. */

cout << "Enter the string to be searched: ";
cin >> str1;

cout << "Enter the target string: ";
cin >> str2;

/* Perform the search. */

ptr = strstr(str1, str2);

if ( ptr ==  NULL )
cout << "No match was found.\n";

else
cout << str2 << " contained in " << str1;
return 0;
}
This doesn't "remove" the offending character, but leaves str2 pointing to the first character in the original str2 contained in str1. You have to be more specific if you want a better answer.

1
2
3
4
5
6
char *end = str2 + strlen(str2);
for ( ; str2 != end; str2++)
{
   if (strstr(str1, str2))
       break;
}

i didn't get what are you saying can you explain me
Topic archived. No new replies allowed.