Writing Via A Temporary File int update_file(char* file_path) { int success = 0; /* assume failure. */ char tmp_file_path[1024]; FILE* fout; sprintf(tmp_file_path, "%s.tmp", file_path); fout = fopen(tmp_file_path, "w"); if (fout) { /* write old data + new data into file... */ . . fclose(fout); if (rename(tmp_file_path, file_path) == 0) success = 1; else unlink(tmp_file_path); /* remove stale */ /* temporary file. */ } return success; }