Wookie68
asked on
Create my_strchr function using pointers
While still on my conquest to understand pointers, I'd like to try and create a function to copy what the STL strchr () would do using pointers within my_strchr ().
Thanks
Thanks
ASKER
Hello ozo -
This is what I have so far and it appears to be working...
char * StrChar(char * s, char c)
{
while(*s && *s != c)
{
s++;
}
if(*s == c)
{
return *s;
}
return (char * ) 0;
}
For your if statement you have, { return (char *)s; } Can you tell me the difference in your line and mine above in the if branch? Thanks
This is what I have so far and it appears to be working...
char * StrChar(char * s, char c)
{
while(*s && *s != c)
{
s++;
}
if(*s == c)
{
return *s;
}
return (char * ) 0;
}
For your if statement you have, { return (char *)s; } Can you tell me the difference in your line and mine above in the if branch? Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help and explanation. Pointers has been a concept that has been hard to grasp, but I figure the more I play with the code, the more I will learn it.
Thanks!
Thanks!
while( *s && *s != c ){
s++;
}
if( *s == c ){ return (char *)s; }
return (char *)0;
}