> because if I use fgets(filename, sizeof(filename),stdin) the pointer bmpInput becomes NULL and the program terminated prematurely. I don't know why.
That would be because fgets() also stores newline as well, and when it tries to find "filename\n", it will fail.
If you had implemented some decent error handling (say calling perror() ), then you might have discovered "file not found" and perhaps figured this out.
Additionally, see the FAQ on how to handle newlines with fgets().
As for the "corruption", you need to post REAL code, not some made-up "something like this" code. If you're not smart enough to figure out the problem, you're not smart enough to make a facsimile program either - the critical information will disappear because you don't know what it is.