c - Passing arguments of getline() from incompatible pointer type -


i know following warnings fault, need bit of working out did wrong. i'm getting: "passing argument 1 of ‘getline’ incompatible pointer type", , same thing argument 2.

here call getline():

getline(&line.buf, &maxsz, stdin) 

here relevant argument declarations:

line_t line; int maxsz = 1000; 

and

typedef struct line_t {   char buf[1000];   int linelength;      int wordcount;   int index; } line_t; 

i believed issue was taking address of meant pointers, upon testing out few different calls getline, yet find solution. think argument 2 fact maxsz not pointer.

while (-1 != (line.linelength = getline((char**) &line.buf, &maxsz, stdin))) {         printf("buf %s\n",line.buf); 

why above giving me infinite loop?

about problem second argument: &maxsz of getline() passing of type int * function getline() expects second argument of type size_t *. change declaration

int maxsz = 1000; 

to

size_t maxsz = 1000; 

about first agrument: recommend replace char buf[1000]; char * buf;. better way read line when don't know it's length. don't forget initialize (i.e. add buf = 0; before calling of getline()). if read description of getline() function find, second parameter not input. maxsz doesn't limit maximal length of string (in variable can find number of characters read, including delimiter character, not including terminating null byte ('\0')). try compile , analyze typical example.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -