Archived

This topic is now archived and is closed to further replies.

johnnyBravo

Using stdio.h, fgets to read a file, how to make it auto read length of each line?

Recommended Posts

johnnyBravo    100
When I used visual basic method of loading text files, it automatically loaded the entire line. Thats what i want to do now. using the: stdio.h, fgets fgets requires me to enter the max length to read on the line. So i want to work out how long the current line is, so my read wrapper method doesnt require the input of how much of the line iwant read. Thanks

Share this post


Link to post
Share on other sites
sbennett    124
The ''max length'' parameter should just be the size of the buffer that you''re reading into. This is so that the fgets function doesn''t write past the end of the buffer and cause your program to crash. If you want to just read the line, no matter how long it is, then look at std::string and std::fstream.

Share this post


Link to post
Share on other sites