Original Post
🔒 Locked
basic c question...
Advertisement
Quote:
Original post by fnm
you dont need to know the exact size of data; instead, declare a buffer big enough to contain a line of data, something like this:
#define I_HOPE_THIS_IS_ENOUGH 1024
char buffer[I_HOPE_THIS_IS_ENOUGH];
fgets(bufer,I_HOPE_THIS_IS_ENOUGH,fp);
Made some edits.
The point being, there's no guarantee you won't be fed a line that's a hundred million characters long.
Quote:
Original post by FreJa
Hi,
I want to use fgets to read from stdin, so:
fgets(str, MAXINT, stdin);
however, I dont know the size of str in advance, so how do I define/alloc it ?
Huge Thanks
Take a look at this usenet entry on Google Groups, which pretty much describes your problem.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement