First of all I'd like to tell that I haven't "looked inside" of the sgets() function. Here is code:
#include <iostream>
#include <stdio.h>
#pragma warning(disable:4996)
int main(){
FILE* file;
int count = 1;
char buf[256];
if (file = fopen("file.txt", "r"))
while (!feof(file))
{
fgets(buf, 256, file);
printf("%d string: %s", count, buf);
++count;
}
fclose(file);
return 0;
}
this is what I wrote in the file.txt:
I
was
born
here
.
And the output in cmd is:
1 string: I
2 string: was
3 string: born
4 string: here
5 string: .
6 string: .
How can I refuse doubling of 5th string?