c - Why does fgets() return a pointer to the newly filled char array? -


i can use fgets in following way:

file *fp = fopen("text.txt", "r"); if(fp == null)   return 1;  char line[50]; fgets(line, 50, fp);  // more stuff 

this fills line expected chars file, why fgets() need return pointer line? line contains data needed use returning pointer it?

because documented in fgets(3) , in posix fgets so.

also, if sure return non-null pointer (i.e. not fail), might use result argument other function. think mistake not test it.

btw, recommend using newer posix getline able deal arbitrarily long lines (as long resources permit it) -and returning on success line length.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -