How does strstr() work?
Yann E. MORIN
yann.morin.1998 at free.fr
Sun Jan 4 15:13:57 UTC 2015
Jody, All,
On 2015-01-04 10:04 -0500, Jody Bruchon spake thusly:
> I was looking at the code for strstr(s1, s2) and I do not understand how it
> does what it's supposed to do. The only exit points return NULL or the
> original pointer to s1. How does strstr() return the pointer to the
> substring it's supposed to be looking for?
You're missing line 35:
23 do {
24 if (!*p) {
25 return (Wchar *) s1;;
26 }
27 if (*p == *s) {
28 ++p;
29 ++s;
30 } else {
31 p = s2;
32 if (!*s) {
33 return NULL;
34 }
35 s = ++s1; <-- here, we modify s1.
36 }
37 } while (1);
Regards,
Yann E. MORIN.
--
.-----------------.--------------------.------------------.--------------------.
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ |
| +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. |
'------------------------------^-------^------------------^--------------------'
More information about the uClibc
mailing list