设为首页 加入收藏

TOP

C/C++面试问题分类大汇总(四)
2014-09-23 08:57:05 来源: 作者: 【 】 浏览:349
Tags:C/C 面试 问题 分类 汇总
urn (*s – *t);

}

strcpy

char *strcpy(char *strDes, const char *strSrc)

{

assert((strDes != NULL) && (strSrc != NULL));

char *address = strDes;

while ((*strDes ++ = *strSrc ++) != ‘\0′)

NULL;

return address;

}

 

strncpy

char *strncpy(char *strDes, const char *strSrc, int count)

{

assert(strDes != NULL && strSrc != NULL);

char *address = strDes;

while (count — && *strSrc != ‘\0′)

*strDes ++ = *strSrc ++;

return address;

}

strlen

int strlen(const char *str)

{

assert(str != NULL);

int len = 0;

while (*str ++ != ‘\0′)

++ len;

return len;

}

strpbrk

char *strpbrk(const char *strSrc, const char *str)

{

assert((strSrc != NULL) && (str != NULL));

const char *s;

while (*strSrc != ‘\0′)

{

s = str;

while (*s != ‘\0′)

{

if (*strSrc == *s)

return (char *) strSrc;

++ s;

}

++ strSrc;

}

return NULL;

}

strstr

char *strstr(const char *strSrc, const char *str)

{

assert(strSrc != NULL && str != NULL);

const char *s = strSrc;

const char *t = str;

for (; *t != ‘\0′; ++ strSrc)

{

for (s = strSrc, t = str; *t != ‘\0′ && *s == *t; ++s, ++t)

NULL;

if (*t == ‘\0′)

return (char *) strSrc;

}

return NULL;

}

strcspn

int strcspn(const char *strSrc, const char *str)

{

assert((strSrc != NULL) && (str != NULL));

const char *s;

const char *t = strSrc;

while (*t != ‘\0′)

{

s = str;

while (*s != ‘\0′)

{

if (*t == *s)

return t – strSrc;

++ s;

}

++ t;

}

return 0;

}

strspn

int strspn(const char *strSrc, const char *str)

{

assert((strSrc != NULL) && (str != NULL));

const char *s;

const char *t = strSrc;

while (*t != ‘\0′)

{

s = str;

while (*s != ‘\0′)

{

if (*t == *s)

break;

++ s;

}

if (*s == ‘\0′)

return t – strSrc;

++ t;

}

return 0;

}

strrchr

char *strrchr(const char *str, int c)

{

assert(str != NULL);

const char *s = str;

while (*s != ‘\0′)

++ s;

for (– s; *s != (char) c; — s)

if (s == str)

return NULL;

return (char *)&

首页 上一页 1 2 3 4 5 6 7 下一页 尾页 4/11/11
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++ 数据结构、算法笔试题 下一篇关于C++ Traints——网易09年笔试..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: