C 模拟函数strchr

1.题目

实现strchr

2.程序代码

#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <Windows.h>
#include <assert.h>

char* my_strchr(char *obj, const char ori)
{
    assert(obj);

    while (*obj != ori)//当obj所指向的元素与ori不等时执行该循环
    {
        obj++;
    }

    return obj;//返回obj此时的地址
}

int main()
{
    char arr[] = "abcdefg";

    printf("%s\n", my_strchr(arr, 'd'));

    system("pause");
    return 0;
}

3.执行结果

这里写图片描述

猜你喜欢

转载自blog.csdn.net/k_a_irving/article/details/80206220