Don't understand why this doesn't work. . .
I'm basically wanting to read a file into a dynamically allocated array. This is the code I'm using to do this, but for some reason the do-while loop that uses fgets to read in the file line by line reads the last line twice for some reason, which gives me an erroneous file length. If anyone could explain why this is happening I would really appreciate it.
Code:
printf( "\n Loading %s into memory. . .\n\n", argv[1] );
char buffer[256];
int length = 0;
do {
fgets( buffer, 256, in );
length += strlen( buffer );
} while( !feof(in) );
char *input_file = malloc( length );
strcpy( buffer, input_file );