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

master
Aadhavan Srinivasan 2 years ago
parent f4f19c7c39
commit 230d26e411

@ -158,9 +158,7 @@ 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; int i = 0;
while (i < buffer->size) { while (i < buffer->size) {
if ((buffer->start - buffer->text) == i) { /* If we have encountered if ((buffer->start - buffer->text) == i) { /* If we have encountered
@ -171,12 +169,9 @@ void save_text_helper(Buffer* buffer,char* filename) {
if (i >= buffer->size) { if (i >= buffer->size) {
break; break;
} }
fputc(*(buffer->text + i),file); fputc(*(buffer->text + i),file);
i++; i++;
} }
}
} }
void init_curses() { void init_curses() {
@ -207,16 +202,12 @@ int main(int argc, char** argv) {
num_of_chars++; num_of_chars++;
} }
} else {
printf("File does not exist.\n");
return -10;
}
while (num_of_chars > 0) { while (num_of_chars > 0) {
buffer_left(buffer); buffer_left(buffer);
num_of_chars--; num_of_chars--;
} }
} }
}
init_curses(); init_curses();
int ch; int ch;
@ -302,8 +293,6 @@ int main(int argc, char** argv) {
} }
continue_while_loop:
} }
endwin(); endwin();
} }

Loading…
Cancel
Save