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

int strrindex(char s[], char t[]) {
    int i, j, k, pos = -1;
    for (i = 0; s[i] != '\0'; i++) {
        for (j = i, k = 0; t[k] != '\0' && s[j] == t[k]; j++, k++);
        if (k > 0 && t[k] == '\0') {
            pos = i;
        }
    }
    return pos;
}

int main() {
    char s[100], t[100];
    printf("请输入字符串s: ");
    scanf("%s", s);
    printf("请输入字符串t: ");
    scanf("%s", t);
    int pos = strrindex(s, t);
    if (pos == -1) {
        printf("字符串s中不含有字符串t\n");
    } else {
        printf("字符串t在字符串s最右边出现的位置是: %d\n", pos);
    }
    return 0;
}
``
c语言编写程序编写一个函数strrindexst用于返回字符串t在字符串s中最右边出现的位置该位置从0开始计数如果s中不含有t那么返回-1;在你编写的程序中使用strrindexst函数输入ts输出t在s最右边的位置

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

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