![]() |
strpos error
Hi there,
Could someone tell me why this aint working? I understand this could be done using strstr() function. I just gave it a try and I cant quite figure out why this piece of code returns NULL though the search string is present in the main string. Please let me know. Thanks, Tina Code:
#include <stdio.h> |
Re: strpos error
If *pb is NULL, do you think "*pb && (*pa == *pb)" will evaluate TRUE or FALSE?
BTW, please use code blocks when posting code. It preserves the formatting and makes it much more readable. |
Re: strpos error
It will evaluate to False. Yea, I figured out my mistake. I changed *pb == '\0' to pb = (b + strlen(b) -1) and it worked.
I'll start using code blocks from my next post. Sorry about that! Thanks! |
Re: strpos error
Quote:
You should change it to pb == (b + strlen(b) -1) not pb = (b + strlen(b) -1) |
Re: strpos error
In my fix I just removed pb from the test, i.e.
Code:
for(pa = a, pb = b; (*pa == *pb); pa++, pb++ )Code:
while (*pb && (*pa == *pb)) |
Re: strpos error
Oops! That's a typo. I meant '==' and that's precisely I've in my code :)
Thanks, Tina |
| All times are GMT +5.5. The time now is 18:09. |