Fixed bug with creating a new file, and then saving it
This commit is contained in:
13
editor.c
13
editor.c
@@ -158,9 +158,7 @@ int is_file(char* path) {
|
||||
}
|
||||
|
||||
void save_text_helper(Buffer* buffer,char* filename) {
|
||||
if (is_file(filename) == 1) {
|
||||
FILE* file = fopen(filename,"w");
|
||||
|
||||
int i = 0;
|
||||
while (i < buffer->size) {
|
||||
if ((buffer->start - buffer->text) == i) { /* If we have encountered
|
||||
@@ -171,14 +169,11 @@ void save_text_helper(Buffer* buffer,char* filename) {
|
||||
if (i >= buffer->size) {
|
||||
break;
|
||||
}
|
||||
|
||||
fputc(*(buffer->text + i),file);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void init_curses() {
|
||||
initscr();
|
||||
noecho();
|
||||
@@ -207,16 +202,12 @@ int main(int argc, char** argv) {
|
||||
num_of_chars++;
|
||||
}
|
||||
|
||||
} else {
|
||||
printf("File does not exist.\n");
|
||||
return -10;
|
||||
}
|
||||
|
||||
while (num_of_chars > 0) {
|
||||
buffer_left(buffer);
|
||||
num_of_chars--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init_curses();
|
||||
int ch;
|
||||
@@ -302,8 +293,6 @@ int main(int argc, char** argv) {
|
||||
|
||||
}
|
||||
|
||||
continue_while_loop:
|
||||
|
||||
}
|
||||
endwin();
|
||||
}
|
||||
|
Reference in New Issue
Block a user