在C语言中,可以使用strchr函数来查找指定字符在字符串中的位置。
函数原型:
char *strchr(const char *s, int c);  参数说明:
返回值:
示例代码:
#include <stdio.h> #include <string.h> int main() { char str[] = "Hello, World!"; char *ptr = strchr(str, 'o'); if (ptr != NULL) { printf("找到字符'o'在字符串中的位置:%d\n", ptr - str); } else { printf("未找到指定字符\n"); } return 0; }  输出结果:
找到字符'o'在字符串中的位置:4