C analog function strchr

1. Topic

implement strchr

2. Program code

#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. Execution results

write picture description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325871317&siteId=291194637