Originally Posted by
SlyMaelstrom
A bunch of problems there. First off, you never declare the use of the std namespace. You shouldn't read a string in with the >> operator. You should use cin.getline(). Secondly, if you had even attempted to compile this, you would have known you're calling your function with the wrong identifier. What the hell is "findchar", you called it "loot_for_char". You also, as I said before, shouldn't use system(), use cin.get() to pause.
Lastly, you can really cut down that function a whole lot by eliminating that temp pointer all together. Consider that your str[val] already points to null if it doesn't point to the correct character.
Thanks for the comment,but what's difference if using cin.getline()? and replacing system() by cin.get()?
here's a recursive version, any suggestion for this one?
Code:
char * look_for_char (char str[], char ch1, int val )
{
char *ptr;
if ((str[val] != ch1)&&(str[val] != '\0')) {val++; return look_for_char (str, ch1,val); }
else return &str[val];
}