zoukankan      html  css  js  c++  java
  • 模式查找

    #include <stdio.h>
    #define MAXLINE 1000
    
    int getline(char line[], int max);
    int strindex(char source[], char searchfor[]);
    
    char pattern[] = "ould";
    
    main()
    {
        char line[MAXLINE];
        int found = 0;
    
        while (getline(line, MAXLINE) > 0)
            if (strindex(line, pattern) >= 0)
            {
                printf("%s", line);
                found++;
            }
        return found;
    }
    
    int getline(char s[], int lim)
    {
        int c, i;
        i = 0;
        while(--lim > 0 && (c = getchar()) != EOF && c != '
    ')
            s[i++] = c;
        if (c == '
    ')
            s[i++] = c;
        s[i] = '';
        return i;
    }
    
    int strindex(char s[], char t[])
    {
        int i, j, k;
        for (i = 0; s[i] != ''; i++)
        {
            for (j=i, k=0; t[k] != '' && s[j] == t[k]; j++,k++)
                 ;
        if (k > 0 && t[k] == '')
            return i;
        }
        return -1;
    }
  • 相关阅读:
    2020 11 21
    2020 11 20
    2020 11 19
    2020 11 18
    2020 11 17
    2020 11 16
    2020 11 15
    2020 11 14
    2020 11 14
    第五周学习进度报告
  • 原文地址:https://www.cnblogs.com/ligongye/p/3411290.html
Copyright © 2011-2022 走看看