• ### Announcements

#### Archived

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

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

## Recommended Posts

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 on other sites
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 on other sites
is there any other way using stdio.h or something maybe? as ive just basically finished my wrapper for the stdio open files way.

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627671
• Total Posts
2978551

• 11
• 10
• 10
• 12
• 22