#include <stdio.h>
#include <string.h>

int main() {
    char str[100];
    char ch;
    printf('请输入一个字符串:');
    scanf('%s', str);
    printf('请输入要检索的字符:');
    scanf(' %c', &ch);

    int len = strlen(str);
    int found = 0;
    for (int i = 0; i < len; i++) {
        if (str[i] == ch) {
            printf('字符 %c 在字符串中的位置为 %d\n', ch, i);
            found = 1;
        }
    }
    if (!found) {
        printf('字符 %c 在字符串中不存在\n', ch);
    }

    return 0;
}
C语言程序:查找字符串中指定字符的位置

原文地址: https://www.cveoy.top/t/topic/pfEz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录