error: parse error before 's'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • strgzr3745
    New Member
    • Jan 2007
    • 2

    error: parse error before 's'

    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*/
  • Soujiro
    New Member
    • Jan 2007
    • 35

    #2
    hmm your code is not so good... better use Code tag so that it would look nice.. anyway you lack a ')' in the while portion.. and i haven't encountered that kind of statement where the description of the parameters are outside the ( ), try putting them inside the ( ) and that should work fine( in gcc linux of course) ...

    well good luck coding

    Comment

    • strgzr3745
      New Member
      • Jan 2007
      • 2

      #3
      Thanks so much for your help! I almost went crazy (^_^) I'll have to check out Code Tag. I just copy pasted my code from my XCode window and all of the indentation was lost. Thanks again!

      Comment

      • cworld
        New Member
        • Jan 2007
        • 15

        #4
        Originally posted by strgzr3745
        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*/
        can not find line 26 . your code is not understandable! !!!!!!1

        Comment

        • RedSon
          Recognized Expert Expert
          • Jan 2007
          • 4980

          #5
          Originally posted by cworld
          can not find line 26 . your code is not understandable! !!!!!!1
          cworld, you sound like a computer giving errors LOL. I think its great!
          [Robot Voice]
          Line 26: bad command or file name. Code is not parseable. Beep!
          [/RobotVoice]

          Comment

          Working...