C语言字符串操作函数-原型 (二)

2014-11-23 22:53:48 · 作者: · 浏览: 9
0)
src++;
tmp++;
count--;
}
return dest;
}

char *strncpy(char *dest, const char *src, size_t count)
{
char *tmp = dest;
assert(src!=NULL && dest!=NULL);
while (count) {
if ((*tmp = *src) != 0)
src++;
tmp++;
count--;
}
return dest;
}


5、strrchr


[cpp]
char *
strrchr (const char *s, int c)
{
register const char *found, *p;

c = (unsigned char) c;

/* Since strchr is fast, we use it rather than the obvious loop. */

if (c == '\0')
return strchr (s, '\0');

found = NULL;
while ((p = strchr (s, c)) != NULL)
{
found = p;
s = p + 1;
}

return (char *) found;
}

char *
strrchr (const char *s, int c)
{
register const char *found, *p;

c = (unsigned char) c;

/* Since strchr is fast, we use it rather than the obvious loop. */

if (c == '\0')
return strchr (s, '\0');

found = NULL;
while ((p = strchr (s, c)) != NULL)
{
found = p;
s = p + 1;
}

return (char *) found;
}