Read the names of people from the file
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Tue, 12 Aug 2008 19:48:19 +0000 (16:48 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Tue, 12 Aug 2008 19:48:19 +0000 (16:48 -0300)
movie.c

diff --git a/movie.c b/movie.c
index 4110fab..4af9eb2 100644 (file)
--- a/movie.c
+++ b/movie.c
@@ -26,6 +26,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
 #include <cairo.h>
 #include <SDL.h>
 #include <SDL_image.h>
@@ -43,6 +45,7 @@
 TTF_Font *font;
 
 SDL_Rect *points;
+char **names;
 int psize;
 int stop = 0;
 
@@ -53,19 +56,25 @@ ReadPoints (char *filename)
   char *buffer;
   char *next;
   size_t len;
+  ssize_t r;
   int i;
   file = fopen (filename, "r");
   fscanf (file, "%d\n", &psize);
   points = malloc (sizeof (SDL_Rect) * psize);
-  if (points == NULL)
+  names = malloc (sizeof (char *) * psize);
+  if (points == NULL || names == NULL)
     abort ();
   buffer = NULL;
   len = 0;
   for (i = 0; i < psize; i++)
   {
-    getline (&buffer, &len, file);
+    r = getline (&buffer, &len, file);
+    buffer[r - 1] = '\0';
     points[i].x = strtol (buffer, &next, 0);
-    points[i].y = strtol (next+1, NULL, 0);
+    points[i].y = strtol (next+1, &next, 0);
+    strtol (next, &next, 0);
+    while (isspace (*next)) next++;
+    names[i] = strdup (next);
   }
   fclose (file);
 }
@@ -224,6 +233,7 @@ main (int argc, char **argv)
   SDL_Surface *image;
   SDL_Surface *slice;
   SDL_Event event;
+  int i;
   ReadPoints ("pro-gnu");
   SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER);
   TTF_Init ();
@@ -247,5 +257,8 @@ main (int argc, char **argv)
   TTF_Quit ();
   SDL_Quit ();
   free (points);
+  for (i = 0; i < psize; i++)
+    free (names[i]);
+  free (names);
   return 0;
 }