From 9c73e6ad68534cfe19330d24504697900d010ba1 Mon Sep 17 00:00:00 2001 From: Lennart Buhl Date: Sat, 2 Nov 2013 20:10:52 +0100 Subject: [PATCH] piece of cake --- src/display.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/display.c b/src/display.c index 95af3a6..bb1ce67 100644 --- a/src/display.c +++ b/src/display.c @@ -24,16 +24,21 @@ void cleanup_display() { char *image; // dimension is width x height */ void print_current_image(struct message* msg, int start, int end) { + end++; // suppress unused warning :-> // end is ignored and 80 is used, should be considered later move(0,0); // start in the upper left corner char *pic = msg->image; // get a ptr to the actual image - for (int row=0; row < 25; row++) { // iterate rows - char *line = (char*) malloc(81); - strcpy(line, strtok(pic, '\n')); // get a line - line[80] = '\0'; // terminate - printw("%s", line+start); + for (int row=0; row < 25; row++) { // iterate over rows + char *original_line; + original_line = strtok(pic, "\n"); + + char *line = (char*) malloc(81); // allocate a line because we modify it + strcpy(line, original_line + start); // get a line from the right start + line[80] = '\0'; // terminate it + printw("%s", line); // print it + free(line); // free it } refresh(); // refresh the screen