Right now I am only trying to get my getline() function to work. I have the code from the book and it seems to be identical, but I cant get it to compile. This is homework but this part should be just copying from the book.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//error list
#define ENDOFFILE = -1;
#define TOOMANYNUMS = -2;
#define LIMIT = 256;
//functions declared
int get_line(char line[], int);
//main
main(){
char line[255];
int num[6];
printf("Please input numbers %c: ", line);
get_line(line,LIMIT);
}
//functions
int get_line(char s[],int lim){
int c, i;
for (i=0;i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
s[i] = c;
if(c=='\n'){
s[i]=c;
++i;
}
s[i]='\0';
return i;
}
Now (edited at 10:22) I only get one error:
18 – expected expression before equal
The problem appears to be that the system you are compiling this on appears to have a
getline()function already defined, and your definition is conflicting with that. It appears that glibc, the C library used on Linux, has a non-standardgetline()function declared instdio.h. It shouldn’t be defined unless you include a line like#define _GNU_SOURCEto opt-in to including non-standard functions, but it may be that this is pre-defined based on how you are compiling your code.The easiest solution would be to rename your function to something else, but you could also try and find in your compiler options why GNU extensions are being turned on.
Now that you’ve edited your code, your second problem is that your
#definelines are wrong. You don’t need an equal or semicolon; these are processed by the preprocessor, which has a different syntax than C, and all you need to do is write#define NAME VALUE.The proper syntax would be: