Fixed bug with creating a new file, and then saving it

master
Aadhavan Srinivasan 2 years ago
parent f4f19c7c39
commit 230d26e411

@ -158,25 +158,20 @@ int is_file(char* path) {
} }
void save_text_helper(Buffer* buffer,char* filename) { void save_text_helper(Buffer* buffer,char* filename) {
if (is_file(filename) == 1) { FILE* file = fopen(filename,"w");
FILE* file = fopen(filename,"w"); int i = 0;
while (i < buffer->size) {
int i = 0; if ((buffer->start - buffer->text) == i) { /* If we have encountered
while (i < buffer->size) { the start of the gap */
if ((buffer->start - buffer->text) == i) { /* If we have encountered i += buffer->gap_size;
the start of the gap */ }
i += buffer->gap_size;
}
if (i >= buffer->size) {
break;
}
fputc(*(buffer->text + i),file); if (i >= buffer->size) {
i++; break;
} }
fputc(*(buffer->text + i),file);
i++;
} }
} }
void init_curses() { void init_curses() {
@ -207,14 +202,10 @@ int main(int argc, char** argv) {
num_of_chars++; num_of_chars++;
} }
} else { while (num_of_chars > 0) {
printf("File does not exist.\n"); buffer_left(buffer);
return -10; num_of_chars--;
} }
while (num_of_chars > 0) {
buffer_left(buffer);
num_of_chars--;
} }
} }
@ -302,8 +293,6 @@ int main(int argc, char** argv) {
} }
continue_while_loop:
} }
endwin(); endwin();
} }

Loading…
Cancel
Save