strcat and strcpy replaced by strncat and strncpy
error messages separated and errno used
the textfile set seems to flush bmp file, have to figure out why...