在终端输入多行信息,找出包含“ould”的行,并打印该行。

如:

Au,love could you and I with fate conspire

To grasp this sorry scheme of things entire,

Would not we shatter it to bitd – and then.


在终端输出上述的文字,输出

Au,love could you and I with fate conspire

Au,love could you and I with fate conspire

To grasp this sorry scheme of things entire,

Would not we shatter it to bitd – and then.

Would not we shatter it to bitd – and then.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define MAX_LINE 1000//最大行

int getline(char line[],int limit)//读取一行
{
	int ch;
	int i = 0;
	
	while (limit && (((ch = getchar()) != '\n' )&&( ch != EOF)))
	{
		line[i] = ch;
		limit--;
		i++;
	}
	
	if (ch == '\n')
	{
		line[i] = ch;
		line[++i] = '\0';//字符串结束标志,strstr函数读取结束标志
	}
	return i;
}

int main()
{
	char line[MAX_LINE];
	
	while (getline(line,MAX_LINE-1))
	{
		if (strstr(line, "ould") != NULL)
		{
			printf("%s", line);
		}
	}
	
	system("pause");
	return 0;
}