I am very new to programming and am trying to get this pattern finder program to compile. Everytime I try I get the following:
error: parse error before 's'
This error appears in line 26 in the getline() function. I have marked where I think this points to. Can anyone bring me back to sanity? I just can't seem to get this to work.
#include <stdio.h>
#define MAXLINE 1000
int index(char s[], char t[]);
int getline(char s[], int lim);
main() /*find all lines matching a pattern*/
{
char line[MAXLINE]; /*1000 long, empty array*/
while (getline(line, MAXLINE) > 0) /*there is a line, fill array*/
if (index(line, "the") >= 0)
printf("Match found on line: %s\n", line);
} /*end of main*/
getline(s, lim) /*get line into s, return length*/
char s[];
int lim;
{
int c, i;
i = 0;
while (--lim > 0 && (c=(getchar()) != EOF && c != '\n') /*limit not exceeded and
not at end of file and not at end of line*/
s[i++] = c; /* ?????PROBLEM HERE?????*/
if (c == '\n')
s[i++] = c; /*put new line into array*/
s[i] = '\0'; /*terminate string with null*/
return(i); /*int, length returned*/
} /*end of getline*/
index(s, t) /*return index of t in s, -1 if none*/
char s[], t[]; /*s=string, t=pattern*/
{
int i, j, k; /*i=march string, j=temp march string, k=march t*/
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); /*int*/
} /*end of for*/
return(-1); /*int*/
} /*end of index*/
error: parse error before 's'
This error appears in line 26 in the getline() function. I have marked where I think this points to. Can anyone bring me back to sanity? I just can't seem to get this to work.
#include <stdio.h>
#define MAXLINE 1000
int index(char s[], char t[]);
int getline(char s[], int lim);
main() /*find all lines matching a pattern*/
{
char line[MAXLINE]; /*1000 long, empty array*/
while (getline(line, MAXLINE) > 0) /*there is a line, fill array*/
if (index(line, "the") >= 0)
printf("Match found on line: %s\n", line);
} /*end of main*/
getline(s, lim) /*get line into s, return length*/
char s[];
int lim;
{
int c, i;
i = 0;
while (--lim > 0 && (c=(getchar()) != EOF && c != '\n') /*limit not exceeded and
not at end of file and not at end of line*/
s[i++] = c; /* ?????PROBLEM HERE?????*/
if (c == '\n')
s[i++] = c; /*put new line into array*/
s[i] = '\0'; /*terminate string with null*/
return(i); /*int, length returned*/
} /*end of getline*/
index(s, t) /*return index of t in s, -1 if none*/
char s[], t[]; /*s=string, t=pattern*/
{
int i, j, k; /*i=march string, j=temp march string, k=march t*/
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); /*int*/
} /*end of for*/
return(-1); /*int*/
} /*end of index*/
Comment