change printf to fprintf