当前位置: 移动技术网 > IT编程>开发语言>C/C++ > C语言;在终端输入多行信息,找出包含“ould”的行,并打印改行。

C语言;在终端输入多行信息,找出包含“ould”的行,并打印改行。

2018年03月03日  | 移动技术网IT编程  | 我要评论

焦化厂主要设备,快乐大本营2012721,3d扫描仪价格

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
#define MAX 1000
int getline(char *line, int limit)
{
 int ch = 0;
 int i = 0;
 while (limit-- && ((ch = getchar()) != EOF) && (ch != '\n'))
 {
  line[i++] = ch;
 }
 if (ch == '\n')
 {
  line[i++] = '\n';
 }
 line[i] = '\0';
 return i;
}
char *my_strstr(char *arr1,char *arr2)
{
 assert(arr1);
 assert(arr2);
 char *p = arr1;
 char *s1 = p;
 char *s2 = arr2;
 while (*s1 != '\0')
 {
  s1 = p;
  s2 = arr2;
  while ((*s1 != '\0') && (*s2 != '\0') && (*s1 == *s2))
  {
   s1 ++;
   s2 ++;
  }
  if (*s2 == '\0')
  {
   return p;
  }
  p++;
 }
 return NULL;
}
  
int main()
{
 char *p = "ould";
 char line[MAX] = {0};
 while (getline(line, MAX - 1))
 {
  if (my_strstr(line, p))
  {
   printf("%s\n", line);
  }
 }
 system("pause");
 return 0;
}

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网