这段代码没报错,怎么输出不了,帮忙看看
/*这段查找每行中含有"ould" 并输出该行的程序怎么执行结果没有输出任何东西 */# include <stdio.h>
# define MAXLINE 1000
int getline(char line[], int max);
int strindex(char source[], char searchfor[]);
char pattern[] = "ould";
int main()
{
char line[MAXLINE];
int found = 0;
while (getchar(line, MAXLINE) > 0)
if (strindex(line, pattern) >= 0)
{
printf("%s", line);
found++;
}
return found;
}
int getline(char line[], int lim)
{
int c, i;
for (i = 0; --lim>0 && (c=getchar())!=EOF && c!='\n'; ++i)
line[i] = c;
if (c == '\n')
line[i++] = c;
line[i] = '\0';
return i;
}
int strindex(char s[], char t[])
{
int i, j, k;
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')
return i;
}
return -1;
}
[ 本帖最后由 cajcak 于 2014-11-4 22:42 编辑 ]