Advertisement
Guest User

Untitled

a guest
Jan 15th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. const char **file_read(char *filename) {
  2.  
  3.     FILE *file = fopen ( filename, "r" );
  4.     char line [ MAX_LINES ]; /* or other suitable maximum line size */
  5.     const char **new_line = malloc(sizeof(char *) * MAX_LINES);
  6.     if ( file != NULL ) {
  7.         int i = 0;
  8.         while ( fgets ( line, sizeof line, file ) != NULL ) /* read a line */
  9.         {
  10.             new_line[i] = strdup(line);
  11.             i++;
  12.         }
  13.     fclose ( file );
  14.     }
  15.     else
  16.     {
  17.         perror ( filename ); /* why didn't the file open? */
  18.     }
  19.     return (const char**) *new_line;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement