Replace unsigned by signed int
Replace sprintf() by snprintf()
Fix fprintf() argument warning
Change variables to constants
Fix exit() argument
Check for errors on fclose()
Check tmpfile() return value