Trimming whitespace from the beginning and ending of a file
A couple lines that bother me:

strncpy(str_buffer, tmp_strstrlen(tmp_str));


First, bear in mind that strncpy does not place a \0 terminator at the end of the string if the buffer size limit is reached (but it does in every other case!).  Thus, you have to be extremely careful when using strncpy.

Second, you're copying a large (256-byte) buffer into a smaller (100-byte) buffer, and you're (presumably) passing the length of the larger buffer to strncpy.  If tmp_str holds a string that's too long, you'll get a buffer overflow.

str_buffer[strlen(str_buffer) - 1] = '\0';


When the string has length zero (e.g. the file is empty or did not have a trailing newline), the array access will be out of range.  Otherwise, it will blindly delete the last character, even if it wasn't whitespace.

The lines that I highlighted will work... if you make a couple assumptions:


Every line of input has &lt; 100 characters
The "whitespace characters" we want to delete always exist.


However, it looks like you're deleting the trailing newline returned by fgets.  I'm not even sure your code works.



If I were you, the first step I'd take is to come up with a concise specification of what you're trying to do.  Correct me if I'm wrong, but it sounds like you want to do this:

first line: s/[\t ]$//
last line:  s/[\t ]$//
Lines are terminated by '\n', except the last line might not have a terminator.


The s/[\t ]$// syntax is borrowed from sed, and means: if there's a '\t' or ' ' character at the end of the string, remove it (i.e. replace it with an empty string).

Then, observe that this operation can be done with a trivial amount of buffering.  When a newline is detected, hang on to the last character in the line, and only emit it when you're not on the first line and you know that more lines follow.  Thus, you don't need an intermediate file.

I recommend implementing a helper function with this signature:

int remove_trailing_spaces(FILE *in, FILE *out);


You should only need to fread and fwrite in large chunks.  The int lets you return an error code if one of these functions fails.