Skip to content

Commit

Permalink
fix cutting lines not ending with \n
Browse files Browse the repository at this point in the history
  • Loading branch information
BigBoot committed Sep 9, 2016
1 parent 77932fc commit 18d8e4a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion text.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,18 @@ int textViewer(char *file) {
char line[MAX_LINE_CHARACTERS];
int length = textReadLine(buffer, line_start, size, line);

CopyEntry *entry = &copy_buffer[copy_current_size];

// Copy line into copy_buffer
memcpy(copy_buffer[copy_current_size].line, &buffer[line_start], length);
memcpy(entry->line, &buffer[line_start], length);

// Make sure line end with a newline
if (entry->line[length - 1] != '\n') {
entry->line[length] = '\n';
length++;
}

// Terminate line
copy_buffer[copy_current_size].line[length] = '\0';

// Remove line
Expand Down

0 comments on commit 18d8e4a

Please sign in to comment.