Fgets compilation error

I'm stuck with what seems a beginner's compilation error:

My simple program:

#include <stdlib.h>
#include <stdio.h>
#include "Tiles_Circular_Linked_List.h"

#define MAX_LINE_LENGTH 128;

int main(int argc, char **argv) {
    struct node *head_tail;
    FILE *file;
    /*char filename[] = "/home/student/Desktop/Studies/C/testing_fodder/tiles";*/

    argv++; /*go to second character-array argument*/

    file = fopen(*argv, "r");
    char *curr_line;

    fgets(curr_line, MAX_LINE_LENGTH, file);

    return 0;
}

I try to compile it using this command:

gcc -g -Wall -ansi launch_tiles.c -o tiles_prog

and get these errors:

launch_tiles.c: In function 'main':

launch_tiles.c:17:19: error: expected ')' before ';' token

launch_tiles.c:17:19: error: too few arguments to function 'fgets' /usr/include/stdio.h:628:14: note: declared here

launch_tiles.c:9:8: warning: variable 'file' set but not used [-Wunused-but-set-variable]

launch_tiles.c:8:15: warning: unused variable 'head_tail' [-Wunused-variable]

I am interested about the errors, not the warnings.

I can count three arguments that I pass to fgets and don't understand where do I miss parentheses so what's the problem?

Thanks!


change

#define MAX_LINE_LENGTH 128;

to

#define MAX_LINE_LENGTH 128

(without the ; ). Easy mistake to make.

The C preprocessor does very simple, textual substitution, so with the wrongly-defined macro, you end up with

fgets(curr_line, 128;, file);

which is obviously a syntax error.

链接地址: http://www.djcxy.com/p/73602.html

上一篇: GCC C编译器警告“警告:控制到达...”

下一篇: Fgets编译错误