现在的位置: 首页 > 综合 > 正文

手动输入n行文本,找出给定字符串最后出现在哪一行?

2013年08月01日 ⁄ 综合 ⁄ 共 455字 ⁄ 字号 评论关闭
//题目:手动输入n行文本,找出给定字符串最后出现在哪一行?
//拓展习题
//找出一篇文章中,关键词,所出现的行以及行号
#include <stdio.h>
#include <string.h>
void readline(const char *SubStr,char *line,int &Hang_Shu)
{
	char temp_str[80];
	int n=0;
	printf("输入文本:\n");
	do
	{
		n++;//记录行数
		gets(temp_str);
		if(strstr(temp_str,SubStr))
		{
			strcpy(line,temp_str);
			Hang_Shu=n;
		}
	}while(strlen(temp_str)>0);
	
}

void main()
{
	char SubStr[80]="包锡元";
	char line[100]="";
	int Hang_Shu=0;
	readline(SubStr,line,Hang_Shu);
	printf("\n最后一个包含给定串为第%d行,内容为:",Hang_Shu);
	puts(line);
}

抱歉!评论已关闭.