Replaced dprintf with sprintf and write.