该程序首先会选择一个字符串str,然后打印不包含该字符串的段落,以输入EOF结束
#include <stdio.h>
#include <stdlib.h>
#define MAXLINE 1000
int strindex(char *bufs, char *pattern);
int getline(char *bufs, int limt);
const char pattern[6] = "hello";
int main()
{
char bufs[MAXLINE];
while(getline(bufs, MAXLINE) > 0)
{
if(strindex(bufs, pattern) == 0)
{
putline(bufs);
}
}
return 0;
}
int getline(char *bufs, int limt)
{
char c = '0';
int i = 0;
while((c = getchar()) != EOF && c != '\n' && i < limt)
{
bufs[i] = c;
i++;
}
if(c == '\n')
{
bufs[i++] = '\n';
}
bufs[i] = '\0';
return i;
}
void putline(char *bufs)
{
int i = 0;
while(bufs[i] != '\0')
{
putchar(bu