-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tony Soul
authored and
Tony Soul
committed
Aug 23, 2016
1 parent
71c0097
commit ffb30f1
Showing
4 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include<stdio.h> | ||
#define MAXLINE 1000 /* maximum input line length */ | ||
|
||
int getline(char line[],int max); | ||
int strindex(char source[],char searchrfor[]); | ||
|
||
char pattern[] ="ould"; /* pattern to search for */ | ||
|
||
/* find all lines matching pattern */ | ||
main() { | ||
char line[MAXLINE]; | ||
int found=0; | ||
|
||
while(getline(line,MAXLINE)>0) | ||
if(strindex(line,pattern)>=0) { | ||
printf("%s",line); | ||
found++; | ||
} | ||
return found; | ||
} | ||
|
||
/* getline: get line into s, return length */ | ||
int getline(char s[],int lim) { | ||
int c,i; | ||
i=0; | ||
while(--lim>0&&(c=getchar()!=EOF)&&c!='\n') | ||
s[i++]=c; | ||
if(c=='\n') | ||
s[i++]=c; | ||
s[i]='\0'; | ||
return i; | ||
} | ||
|
||
/* strindex: return index of t in s, -1 if none */ | ||
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; | ||
} |