Quote:
Originally Posted by
shamrock
Because the second argument of fgets is an integer while malloc returns pointer to void so take it out...
The problem is much deeper than that.
The given program allocates enough space to hold a pointer to a character; not enough space to read a line of user input. And, I don't see how eracav can preallocate space for "
unlimited input from the user". In addition to that, eracav isn't checking the return value of malloc() to determine if space was allocated nor of fgets() to determine if an error or EOF has been encountered before a <newline> was found.
To do what needs to be done, eracav will need much more complicated logic with a loop calling fgets() and realloc() to increase the input buffer size until a <newline> or EOF has been copied into the growing buffer.
Is this a homework assignment?