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 "); if(strindex(line, pattern) >= 0){ printf("%s", line); found++; printf("run here2 "); } } return found; } int add_getline(char s[], int lim) { int c, i; i = 0; while(--lim > 0 && (c=getchar()) != EOF && c != ' ') //EOF:ctrl+d, ' ':enter s[i++] = c; if(c == ' ') s[i++] = c; s[i] = '