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

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -