Hi all,
i'm writing this code that will prompt the user for a cstring of 25 chars...store it and prompt a char to find...then with a function search for that char from the cstring.
i got it working with a while loop, but only if i enter a char thats part of the cstring. if i enter a character that's not part of the cstring, that is invalid, i can't figure that out in the loop?
int find(char* p_cString, char valueToFind)
{
cStringLength(p_cString);
char* currentElementPtr = p_cString;
currentElementPtr = strchr (p_cString, valueToFind);
while (currentElementPtr != NULL)
{
cout << "\n\nSearch resulted in index of " << (currentElementPtr - p_cString) << ".\n";
currentElementPtr = strchr (currentElementPtr + 1, valueToFind);
cout << "(any number outside of 0 to " << cStringLength(p_cString);
cout << " means that '" << valueToFind << "' does not exist in\n\"";
cout << p_cString << "\")"".\n\n";
}
return 0;
}
any help would be greatly appreciated.
Thanks!