can now save to file

master
bx 2022-04-02 14:58:16 +00:00
parent bd0198b407
commit 64be24496e
4 changed files with 20 additions and 0 deletions

17
c_save.c 100644
View File

@ -0,0 +1,17 @@
void
c_save(char *file) {
FILE *f = fopen(file + 2, "w");
if(f == NULL) { puts("couldnt open file."); return; }
Row *row = buffer;
while (1) {
for(int i = 0; i < ROW_SIZE; i++) {
if (row->text[i] == '\0' || row->text[i] == '\n')
break;
fwrite(&row->text[i], 1, 1, f);
}
fwrite("\n", 1, 1, f);
if (row->n == NULL) break;
row = row->n;
}
}

View File

@ -6,3 +6,4 @@ NULL,
['w'] = c_writeline,
['q'] = NULL,
['Q'] = c_quit,
['S'] = c_save,

1
efn.c
View File

@ -20,3 +20,4 @@
#include "c_writeline.c"
#include "b_getline.c"
#include "c_save.c"

1
efn.h
View File

@ -12,3 +12,4 @@ void c_print(char *);
Row *b_insert(Row *);
Row *b_getline(Row *, int);
void c_writeline(char *);
void c_save(char*);