Is this a safe way to trim the newline character off of a line after reading it in from a file?
while ( fgets(buffer, 1024, fp) != NULL )
{
buffer[strlen(buffer)-1] = '\0';
fprintf (stderr, "%s\n", buffer);
}
It doesn't give me any seg faults but could it cause problems down the road? Should I do something like this instead?
while ( fgets(buffer, 1024, fp) != NULL )
{
tmp = (char *) malloc(strlen(buffer));
strncpy(tmp, buffer, strlen(buffer) - 1);
tmp[strlen(buffer)-1] = '\0';
fprintf (stderr, "%s\n", tmp);
}