How can know if the end of line in C

c

Solution

According to http://en.cppreference.com/w/c/io/fgets

Reads at most count - 1 characters from the given file stream and stores them in str. 
Parsing stops if end-of-file occurs or a newline character is found, in which case str will contain that newline character.

So, once fgets returns, there are 3 possibilities

- LENGTH_LINE was reached

- We got a newline

- EOF was reached.

I'm assuming you have a line in cases 2 and 3.

In this case the detection condition is :

line[len-1] == '\n' || feof(fp)

Problem

If I do : ``` int main(){ const int LENGTH_LINE = 100; char line[LENGTH_LINE]; int len; FILE* fp = fopen(file.txt,"r"); fgets(line,LENGTH_LINE,fp); len = strlen(line); if(line[len-1] == '\n') printf("I've a line"); //This work if the line have \n , but if the end line of the text dont have \n how can do it? } ``` I need to know if I take a whole line with `fgets` because I got a delimiter.

Original source