File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -407,15 +407,23 @@ corrective actions to be taken in each case, assuming that
407407static long anomalies; /* problems accumulated by |save_graph| */
408408static FILE *save_file; /* the file being written */
409409
410- @ @<External f...@>=
410+ @ We open the file in binary mode. This makes no difference on
411+ UNIX-like operating systems; but it prevents Windows-like systems
412+ from converting the single internal character |'\n'| to the
413+ two external characters |'\r'| and |'\n'|.
414+ (Indeed, with text mode, a graph saved under Windows
415+ cannot be restored under Linux!
416+ But with binary mode that problem goes away.)
417+
418+ @<External f...@>=
411419long save_graph(g,f)
412420 Graph *g; /* graph to be saved */
413421 char *f; /* name of the file to be created */
414422{@+@<Local variables for |save_graph|@>@;@#
415423 if (g==NULL || g->vertices==NULL) return -1; /* where is |g|? */
416424 anomalies=0;
417425 @<Figure out the extent of |g|'s internal records@>;
418- save_file=fopen(f,"w ");
426+ save_file=fopen(f,"wb ");
419427 if (!save_file) return -2; /* oops, the operating system won't cooperate */
420428 @<Translate |g| into external format@>;
421429 @<Make notes at the end of the file about any changes that were necessary@>;
You can’t perform that action at this time.
0 commit comments