Hello all,
I have been trying to debug and get this last error fixed for the past several hours. The following are the errors I am receiving when debugging:
pattern.c:11: warning: passing argument 2 of ‘index’ makes integer from pointer without a cast
pattern.c: At top level:
pattern.c:31: error: conflicting types for ‘index’
line 11 pertains to if (index(line, "the") >= 0)
line 31 to int index(char s[], char t[])
I am hoping this is a easy fix. But have tried and searched for hours and have not been successful. If you could help lead me in the right direction, I would greatly appreciate it! The program basically searches for a pattern consisting of "the". Then prints the entire line which contains "the".
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLINE 1000
main()
{
char line[MAXLINE];
while (getline(line, MAXLINE) > 0)
if (index(line, "the") >= 0)
printf("%s", line);
}
getline(s, lim)
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);
}
int index(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 (t[k] == '\0')
return(i);
}
return(-1);
}