memcpy、strstr库函数实现

来源:互联网 发布:淘宝网健身护腕 编辑:程序博客网 时间:2024/04/30 11:36

memcpy、strstr库函数实现

#include <iostream>    // 数据流输入/输出#include <cstdio>      // 定义输入/输出函数using namespace std;void *memcpy(void *dest, void *src, size_t count){char *tmp =(char *) dest;const char *s = (char *) src;while (count>0){*tmp++ = *s++;--count;}return dest;}// 函数返回一个指针,它指向字符串str2 首次出现于字符串str1中的位置,如果没有找到,返回NULL。char *strstr(const char *s1, const char *s2){int n;if (*s2){while (*s1){for (n=0; *(s1 + n) == *(s2 + n); n++){if (!*(s2 + n + 1))return (char *)s1;}s1++;}return NULL;}elsereturn (char *)s1;}int main(){cout << strstr("Hello world!" ,"lo w")<< endl;return 0;}


原创粉丝点击