Created
May 17, 2010 19:43
-
-
Save LTe/404146 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
char* readline(FILE* f) | |
{ | |
/* | |
* calloc is like malloc, except it allocates cleared memory | |
* so you don't have random bytes in the memory space | |
*/ | |
char* line = (char*) calloc(0, sizeof(char) );; | |
char c; | |
int len = 0; | |
/* | |
* If the readline reaches the end of a file, | |
* I want it to stop just the same | |
*/ | |
while ( (c = fgetc(f) ) != EOF && c != '\n') | |
{ | |
/* | |
* The actual size allocated needs to be 1 more | |
* character than the string itself because '\0' | |
* needs to be added to the end of the string | |
* to prevent garbage | |
*/ | |
line = (char*) realloc(line, sizeof(char) * (len + 2) ); | |
line[len++] = c; | |
line[len] = '\0'; | |
} | |
if(c == EOF) | |
return EOF; | |
else | |
return line; | |
} | |
FILE *plik; | |
char* tytul; | |
char* opis; | |
movie_file = fopen("plik", r) | |
if(movie_file == NULL) | |
{ | |
// BRAK PLIKU | |
} | |
else | |
{ | |
while(tytul = readline(movie_file) != EOF) | |
{ | |
opis = readline(movie_file); | |
super_funkcja(tytul, opis); | |
} | |
fclose(movie_file); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment