Java教程

实验11-1-6 指定位置输出字符串 (20 分)

本文主要是介绍实验11-1-6 指定位置输出字符串 (20 分),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#include <stdio.h>

#define MAXS 10

char *match(char *s, char ch1, char ch2);

int main()
{
    char str[MAXS], ch_start, ch_end, *p;

    scanf("%s\n", str);
    scanf("%c %c", &ch_start, &ch_end);
    p = match(str, ch_start, ch_end);
    printf("%s\n", p);

    system("pause");
    return 0;
}

/* 你的代码将被嵌在这里 */
char *match(char *s, char ch1, char ch2) {
    while (*s != ch1 && *s)
        s++;
    char *p = s;
    while (*s != ch2 && *s)
        printf("%c", *s++);
    if (*s == ch2)
        printf("%c\n", *s);
    if (*s == '\0')
        printf("\n");
    while (*p)
        printf("%c", *p++);
}

此算法或许有更好的方式。

这篇关于实验11-1-6 指定位置输出字符串 (20 分)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!