标签:
4.1
#include <stdio.h> #define MAXLINE 1000 int add_getline(char line[], int max); int strindex(char source[], char searchfor[]); char pattern[] = "ray"; int main(void) { char line[MAXLINE]; int found = 0; while(add_getline(line, MAXLINE) > 0){ printf("run here1\n"); if(strindex(line, pattern) >= 0){ printf("%s", line); found++; printf("run here2\n"); } } return found; } int add_getline(char s[], int lim) { int c, i; i = 0; while(--lim > 0 && (c=getchar()) != EOF && c != ‘\n‘) s[i++] = c; if(c == ‘\n‘) s[i++] = c; s[i] = ‘\0‘; printf("run here3 i:%d\n", i); return i; } int strindex(char s[], char t[]) { int i, j, k; printf("run here4\n"); for(i = 0; s[i] != ‘\0‘; i++){ printf("run here5\n"); for(j=i, k=0; t[k]!=‘\0‘ && s[j]==t[k]; j++, k++) printf("s[%d]=%c, t[%d]=%c\n", j,s[j],k, t[k]); if(k > 0 && t[k] == ‘\0‘){ printf("k:%d\n",k); return i; } } printf("run here6\n"); return -1; }
标签:
原文地址:http://www.cnblogs.com/try-again/p/4998200.html