diff options
author | KatolaZ <katolaz@freaknet.org> | 2019-08-01 16:42:36 +0100 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2019-08-01 16:42:36 +0100 |
commit | 82a7c12e8338288ccb40d213fcc9e15d102aa968 (patch) | |
tree | 970ca2f39dc599624e53a10e59d05bc908f9b0a2 /files.c | |
parent | 62713aaf65264950aecad9237d50e911d7dad893 (diff) |
remove trailing blank lines in write_file - change check_bound
Diffstat (limited to 'files.c')
-rw-r--r-- | files.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -7,7 +7,7 @@ void write_file(FILE *fc){ FILE *fout; - int i; + int i, ne; if (!fname[0] || force_new){ get_string(fc, "Write to: ", fname, 255); @@ -23,8 +23,16 @@ void write_file(FILE *fc){ get_key(fc, "Error opening file."); return; } + ne = 0; for (i=0; i<HEIGHT; i++){ - fprintf(fout, "%s\n", screen.l[i].s); + if (strlen(screen.l[i].s)){/* remove trailing blank lines */ + /* put the empty lines preceeding the current non-empty one */ + while (ne--) + fprintf(fout, "\n"); + fprintf(fout, "%s\n", screen.l[i].s); + ne = 0; + } + else ne++; } fclose(fout); modified = 0; @@ -51,7 +59,7 @@ void load_file(FILE *fc){ if ((fin=fopen(newfname, "r")) != NULL){ i = 0; while((fgets(screen.l[i].s, WIDTH+1, fin)) != NULL && i<HEIGHT){ - screen.l[i].lst = strlen(screen.l[i].s) - 1; + screen.l[i].lst = strlen(screen.l[i].s) - 2; screen.l[i].n = i; screen.l[i].s[strlen(screen.l[i].s)-1]='\0'; i++; |