C语言模拟实现标准库函数之strchr()

strchr()

查找字符串s中首次出现字符c的位置


char * my_strchr(char *str1, char str2)
{
    while (*str1 != str2 && *str1 != NULL)
    {
        str1++;
    }
    return str1;
}

int main()
{
    char string[17];
    char *ptr, c = 'r';
    strcpy(string, "Thisisastring");
    ptr = my_strchr(string, c);
    if (ptr)
        printf("The character %cis at position:%s\n", c, ptr);
    else
        printf("The character was not found\n");
    system("pause");
    return 0;
}

你可能感兴趣的:(C语言模拟实现标准库函数,C语言模拟实现标准库函数,strchr())