#include <stdio.h>
#include <string.h>
#define MAXLINE 1000
int getlines(char line[],int max);
int strindex(char source[],char searchfor[]);
char pattern[] = "ould"; /*pattern to search for */
/*find all lines matching pattern */
int main(void)
{
char line[MAXLINE];
int k;
int found = 0;
while(getlines(line,MAXLINE) > 0){
if((k = strindex(line,pattern)) >= 0)
printf("%c",line[k]);
found++;
}
else
printf("%d\n",k);
}
return found;
}
int getlines(char s[],int lim)
{
int i,c;
i = 0;
while(--lim > 0 && (c = getchar()) != EOF && c != '\n')
s[i++] = c;
if(c == '\n')
s[i++] = c;
s[i] = '\0';
return i;
}
int strindex(char *s,char *t)
{
int i,j,k;
for(i = strlen(s) - 1; i >= 0; i--){
for(j = i,k = strlen(t)-1; k >= 0 && s[j] == t[k];k--,j--)
;
if(k < 0)
return (j+1);
}
return -1;
}
#include <string.h>
#define MAXLINE 1000
int getlines(char line[],int max);
int strindex(char source[],char searchfor[]);
char pattern[] = "ould"; /*pattern to search for */
/*find all lines matching pattern */
int main(void)
{
char line[MAXLINE];
int k;
int found = 0;
while(getlines(line,MAXLINE) > 0){
if((k = strindex(line,pattern)) >= 0)
{
printf("%s\n%d\n",line,k);
for(; line[k] != '\0';k++)printf("%c",line[k]);
found++;
}
else
printf("%d\n",k);
}
return found;
}
int getlines(char s[],int lim)
{
int i,c;
i = 0;
while(--lim > 0 && (c = getchar()) != EOF && c != '\n')
s[i++] = c;
if(c == '\n')
s[i++] = c;
s[i] = '\0';
return i;
}
int strindex(char *s,char *t)
{
int i,j,k;
for(i = strlen(s) - 1; i >= 0; i--){
for(j = i,k = strlen(t)-1; k >= 0 && s[j] == t[k];k--,j--)
;
if(k < 0)
return (j+1);
}
return -1;
}