NO, fgets stops reading after it encounters a \n (new line) character.
Otherwise, you must find and remove the newline yourself.
Or you can use fread:
The C library function size_t fread(void *ptr, size_t size, size_t
nmemb, FILE *stream) reads data from the given stream into the array
pointed to, by ptr.
The total number of elements successfully read are returned as a
size_t object, which is an integral data type. If this number differs
from the nmemb parameter, then either an error had occurred or the End
Of File was reached.
/* fread example: read an entire file */
#include <stdio.h>
#include <stdlib.h>
int main () {
FILE * pFile;
long lSize;
char * buffer;
size_t result;
pFile = fopen ( "myfile.bin" , "rb" );
if (pFile==NULL) {fputs ("File error",stderr); exit (1);}
// obtain file size:
fseek (pFile , 0 , SEEK_END);
lSize = ftell (pFile);
rewind (pFile);
// allocate memory to contain the whole file:
buffer = (char*) malloc (sizeof(char)*lSize);
if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}
// copy the file into the buffer:
result = fread (buffer,1,lSize,pFile);
if (result != lSize) {fputs ("Reading error",stderr); exit (3);}
/* the whole file is now loaded in the memory buffer. */
// terminate
fclose (pFile);
free (buffer);
return 0;
}
fgets()is concerned, it will stop once, it gets either a new-line character or an end-of-file.getlinebehaves likefgets, expect that it manages the memory for you. It won't solve the newline problem. (Butgetdelimwith a null delimiter might work. Both are non-standard functions, though.)fgetsis not the only function that reads data from a file. If you want the entire file in memory, justreadit in its entirety. (Best make sure you allocated enough memory.)getlinewhere one can specify the delimiter.