mystring.c, rewrite spos_()

This commit is contained in:
rlar 2014-05-24 12:40:52 +02:00
parent 27cb51afca
commit d17c0d7813
1 changed files with 3 additions and 6 deletions

View File

@ -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;
}