C programming. If I am using fgets(line, MAXLINE, stdin) function in a loop, should I zero-out line each time before a new iteration? -


if using fgets(line, maxline, stdin) function in loop, should zero-out line each time before new iteration? meaning have smth

char *line = calloc(maxline+1, 1);     while (fgets(line, maxline+1, stdin)) {         ...     } 

is required reallocate or zero-out line char string before next call of fgets?

thank

no. fgets guarantees 0 termination on successful read. loop condition handles unsuccessful case. completeness, should check calloc worked though.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -