void c_open(char *file, char **argv) { if(argv[1] == NULL) { puts("usage: O filename"); return;} FILE *f = fopen(argv[1], "r"); if(f == NULL) { puts("couldnt open file."); return; } b_truncate(buffer); Row *row = buffer; while (1) { size_t red = 0; for (int i = 0; i < ROW_SIZE; i++) { red = fread(&row->text[i], 1, 1, f); if (red != 1) return; if (row->text[i] == '\n') { row->text[i] = 0; break; } } row = b_insert(row); } fclose(f); } void c_save(char *file, char **argv) { 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; } }