summaryrefslogtreecommitdiff
path: root/files.c
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2019-08-01 16:42:36 +0100
committerKatolaZ <katolaz@freaknet.org>2019-08-01 16:42:36 +0100
commit82a7c12e8338288ccb40d213fcc9e15d102aa968 (patch)
tree970ca2f39dc599624e53a10e59d05bc908f9b0a2 /files.c
parent62713aaf65264950aecad9237d50e911d7dad893 (diff)
remove trailing blank lines in write_file - change check_bound
Diffstat (limited to 'files.c')
-rw-r--r--files.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/files.c b/files.c
index 17743a5..dfeb3b2 100644
--- a/files.c
+++ b/files.c
@@ -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++;