| <html lang="en"> | |
| <head> | |
| <title>fgets - Untitled</title> | |
| <meta http-equiv="Content-Type" content="text/html"> | |
| <meta name="description" content="Untitled"> | |
| <meta name="generator" content="makeinfo 4.13"> | |
| <link title="Top" rel="start" href="index.html#Top"> | |
| <link rel="up" href="Stdio.html#Stdio" title="Stdio"> | |
| <link rel="prev" href="fgetpos.html#fgetpos" title="fgetpos"> | |
| <link rel="next" href="fgetwc.html#fgetwc" title="fgetwc"> | |
| <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> | |
| <meta http-equiv="Content-Style-Type" content="text/css"> | |
| <style type="text/css"><!-- | |
| pre.display { font-family:inherit } | |
| pre.format { font-family:inherit } | |
| pre.smalldisplay { font-family:inherit; font-size:smaller } | |
| pre.smallformat { font-family:inherit; font-size:smaller } | |
| pre.smallexample { font-size:smaller } | |
| pre.smalllisp { font-size:smaller } | |
| span.sc { font-variant:small-caps } | |
| span.roman { font-family:serif; font-weight:normal; } | |
| span.sansserif { font-family:sans-serif; font-weight:normal; } | |
| --></style> | |
| </head> | |
| <body> | |
| <div class="node"> | |
| <a name="fgets"></a> | |
| <p> | |
| Next: <a rel="next" accesskey="n" href="fgetwc.html#fgetwc">fgetwc</a>, | |
| Previous: <a rel="previous" accesskey="p" href="fgetpos.html#fgetpos">fgetpos</a>, | |
| Up: <a rel="up" accesskey="u" href="Stdio.html#Stdio">Stdio</a> | |
| <hr> | |
| </div> | |
| <h3 class="section">4.12 <code>fgets</code>—get character string from a file or stream</h3> | |
| <p><a name="index-fgets-168"></a><a name="index-g_t_005ffgets_005fr-169"></a><strong>Synopsis</strong> | |
| <pre class="example"> #include <stdio.h> | |
| char *fgets(char *<var>buf</var>, int <var>n</var>, FILE *<var>fp</var>); | |
| #include <stdio.h> | |
| char *_fgets_r(struct _reent *<var>ptr</var>, char *<var>buf</var>, int <var>n</var>, FILE *<var>fp</var>); | |
| </pre> | |
| <p><strong>Description</strong><br> | |
| Reads at most <var>n-1</var> characters from <var>fp</var> until a newline | |
| is found. The characters including to the newline are stored | |
| in <var>buf</var>. The buffer is terminated with a 0. | |
| <p>The <code>_fgets_r</code> function is simply the reentrant version of | |
| <code>fgets</code> and is passed an additional reentrancy structure | |
| pointer: <var>ptr</var>. | |
| <p><br> | |
| <strong>Returns</strong><br> | |
| <code>fgets</code> returns the buffer passed to it, with the data | |
| filled in. If end of file occurs with some data already | |
| accumulated, the data is returned with no other indication. If | |
| no data are read, NULL is returned instead. | |
| <p><br> | |
| <strong>Portability</strong><br> | |
| <code>fgets</code> should replace all uses of <code>gets</code>. Note however | |
| that <code>fgets</code> returns all of the data, while <code>gets</code> removes | |
| the trailing newline (with no indication that it has done so.) | |
| <p>Supporting OS subroutines required: <code>close</code>, <code>fstat</code>, <code>isatty</code>, | |
| <code>lseek</code>, <code>read</code>, <code>sbrk</code>, <code>write</code>. | |
| <p><br> | |
| </body></html> | |