Having a closer look, what are you trying to do? This looks bad in so many ways. Give a better description of what you are intending and ill mock up a revision.
EDIT: Are you trying to find the sub string "udo"?
#include <iostream>
usingnamespace std;
int FindSubString(char string1[], char string2[])
{
for (int i = 0; string1[i] != '\0'; i++) // while string remains in bounds
{
for (int j = 0; string2[j] == string1[i+j]; j++)
// while both characters in each string are equal
// contiue to check equallity of subsequent characters
{
if (string2[j+1] == '\0')
// when the next character is a null terminator of second string you will know
// second string is equal to the sub string starting at [i].
{
return i; // return the index where substring started
}
}
}
return -1;
}
int main()
{
char string1[] = "howudoing?"; // first string of characters
char string2[] = "udo"; // second string of characters
char *p_Character = NULL; // pointer to a character initialized with NULL
int index = FindSubString(string1, string2);
// I am passing the array in and not just the first element.
// & address of operator is not needed as arrays are pointers to elements.
if (index != -1)
// checks for match of strings
{
p_Character = &string1[index];
// assign the pointer to the memory address of character
// at string1[index].
cout << *p_Character;
// output value at address.
}
return 0;
}