Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const char **file_read(char *filename) {
- FILE *file = fopen ( filename, "r" );
- char line [ MAX_LINES ]; /* or other suitable maximum line size */
- const char **new_line = malloc(sizeof(char *) * MAX_LINES);
- if ( file != NULL ) {
- int i = 0;
- while ( fgets ( line, sizeof line, file ) != NULL ) /* read a line */
- {
- new_line[i] = strdup(line);
- i++;
- }
- fclose ( file );
- }
- else
- {
- perror ( filename ); /* why didn't the file open? */
- }
- return (const char**) *new_line;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement