diff --git a/text.c b/text.c index f561d193..6101b842 100644 --- a/text.c +++ b/text.c @@ -530,8 +530,18 @@ int textViewer(char *file) { char line[MAX_LINE_CHARACTERS]; int length = textReadLine(buffer, line_start, size, line); + CopyEntry *entry = ©_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