mystring.c, rewrite spos_()
This commit is contained in:
parent
27cb51afca
commit
d17c0d7813
|
|
@ -589,14 +589,11 @@ absi(long i)
|
|||
|
||||
int
|
||||
spos_(char *sub, const char *s)
|
||||
/* equivalent to Turbo Pascal pos().
|
||||
BUG: counts 1 ... length(s), not from 0 like C
|
||||
*/
|
||||
{
|
||||
char *ptr;
|
||||
const char *ptr = strstr(s, sub);
|
||||
|
||||
if ((ptr = strstr(s, sub)) != NULL)
|
||||
return (int) (strlen(s) - strlen(ptr));
|
||||
if (ptr)
|
||||
return (int) (ptr - s);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue