I just started programming and have a beginner question, I want to write a function to read a file with unknown length line by line. Since I wouldn't know the length of each line so I used getline()
function:
void readDict(FILE *dict_file){
//Read dic
char *line;
size_t len = 0, read;
while((read = getline(&line, &len, dict_file))!=-1){
check(line);
}
free(line);
return;
}
Since getline()
is kind of similar to malloc()
and realloc()
a string, so if I keep using this function to read a lot of line with unknown length, would I get a memory leak or out of memory?
malloc
memory forline
before callinggetline
. – Biographer