wos*_*hen 8 c pointers getline dynamic-memory-allocation
我刚刚开始编程并有一个初学者的问题,我想编写一个函数来逐行读取未知长度的文件.因为我不知道每行的长度所以我使用了getline()函数:
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;
}
Run Code Online (Sandbox Code Playgroud)
因为getline()有点类似于malloc()和realloc()字符串,所以如果我继续使用这个函数来读取很多未知长度的行,我会得到内存泄漏还是内存不足?