-4

I would like to read text files line by line in c. I saw some examples using fgets. But I don't know if the fgets reads the caracteres until the end of the line, or it will read the amunt of chactrers specified (without stoping at the end of the line).

Best regards.

Zaratruta
  • 2,097
  • 2
  • 20
  • 26

2 Answers2

0

One of many references located here.

fgets - char * fgets ( char * str, int num, FILE * stream );

Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or the end-of-file is reached, whichever happens first.

A newline character makes fgets stop reading, but it is considered a valid character by the function and included in the string copied to str.

Many code examples out there.

static_cast
  • 1,174
  • 1
  • 15
  • 21
0

For future, if you're using a vim editor, try using man fgets. It'll give you some basic info on the function and its parameters. You can use this on literally any function that you're unsure about and it may help to clear some things up (although in my experience it confused things a bit more sometimes since I'm also a beginner)

fgets reads until either a null-byte (basically '\0'), the new line character or until it reaches the end of the file.

OznOg
  • 4,440
  • 2
  • 26
  • 35
  • Using vim has _nothing_ to do with using manpages. If you work on almost any non-Windows system, you should know how and when to use a manpage. – 0xdd Nov 13 '18 at 20:00