I try read a story text file using c. the problem is i want one paragraf in one variabel. i am confuse how much i should alocate the buffer size?
Unless you know how many characters in your paragraph, you can't just allocate a buffer. As AD suggests, you can set up an array of pointers, assuming you know how many paragraphs you need. There's another function you can use named realloc()
. You malloc()
for the first line you read, then realloc()
to add more space for each line additional line you read. When you get to the end of the paragraph, increment the paragraph count (like AD did) and start again with a new malloc()
.