As this answer says, you omitted the line that declares the main
function.
This line:
int getline(char *line, int max);
is a declaration of the getline
function, which must be defined elsewhere. (If you dropped the ;
, it could also be the first line of a full definition of getline
, but that doesn't seem to be the intent.)
In this case, the intent appears to be for it to be defined in a different source file. You'll need to compile both that source file and this one, and then use the linker to combine them into an executable program.
You may run into another problem, though. Some implementations provide their own non-standard function called getline
, and it's not compatible with the way you've declared it. If you're using gcc, you'll need to compile with an option that inhibits that non-standard definition, such as -ansi
or -std=c99
. For simplicity, you might consider using a name other than getline
; get_line
should be ok.
And of course you'll need to define the getline
or get_line
function somewhere. (You can put the definition in the same source file if you like, but I suspect the point of this exercise is to build programs from multiple source files.)