Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

127 lines
5.6KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>fgets (The Red Hat newlib C Library)</title>
  7. <meta name="description" content="fgets (The Red Hat newlib C Library)">
  8. <meta name="keywords" content="fgets (The Red Hat newlib C Library)">
  9. <meta name="resource-type" content="document">
  10. <meta name="distribution" content="global">
  11. <meta name="Generator" content="makeinfo">
  12. <link href="index.html#Top" rel="start" title="Top">
  13. <link href="Document-Index.html#Document-Index" rel="index" title="Document Index">
  14. <link href="Document-Index.html#SEC_Contents" rel="contents" title="Table of Contents">
  15. <link href="Stdio.html#Stdio" rel="up" title="Stdio">
  16. <link href="fgetwc.html#fgetwc" rel="next" title="fgetwc">
  17. <link href="fgetpos.html#fgetpos" rel="prev" title="fgetpos">
  18. <style type="text/css">
  19. <!--
  20. a.summary-letter {text-decoration: none}
  21. blockquote.indentedblock {margin-right: 0em}
  22. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  23. blockquote.smallquotation {font-size: smaller}
  24. div.display {margin-left: 3.2em}
  25. div.example {margin-left: 3.2em}
  26. div.lisp {margin-left: 3.2em}
  27. div.smalldisplay {margin-left: 3.2em}
  28. div.smallexample {margin-left: 3.2em}
  29. div.smalllisp {margin-left: 3.2em}
  30. kbd {font-style: oblique}
  31. pre.display {font-family: inherit}
  32. pre.format {font-family: inherit}
  33. pre.menu-comment {font-family: serif}
  34. pre.menu-preformatted {font-family: serif}
  35. pre.smalldisplay {font-family: inherit; font-size: smaller}
  36. pre.smallexample {font-size: smaller}
  37. pre.smallformat {font-family: inherit; font-size: smaller}
  38. pre.smalllisp {font-size: smaller}
  39. span.nolinebreak {white-space: nowrap}
  40. span.roman {font-family: initial; font-weight: normal}
  41. span.sansserif {font-family: sans-serif; font-weight: normal}
  42. ul.no-bullet {list-style: none}
  43. -->
  44. </style>
  45. </head>
  46. <body lang="en">
  47. <a name="fgets"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="fgetwc.html#fgetwc" accesskey="n" rel="next">fgetwc</a>, Previous: <a href="fgetpos.html#fgetpos" accesskey="p" rel="prev">fgetpos</a>, Up: <a href="Stdio.html#Stdio" accesskey="u" rel="up">Stdio</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  51. </div>
  52. <hr>
  53. <a name="fgets_002c-fgets_005funlocked_002d_002d_002dget-character-string-from-a-file-or-stream"></a>
  54. <h3 class="section">4.12 <code>fgets</code>, <code>fgets_unlocked</code>&mdash;get character string from a file or stream</h3>
  55. <a name="index-fgets"></a>
  56. <a name="index-fgets_005funlocked"></a>
  57. <a name="index-_005ffgets_005fr"></a>
  58. <a name="index-_005ffgets_005funlocked_005fr"></a>
  59. <p><strong>Synopsis</strong>
  60. </p><div class="example">
  61. <pre class="example">#include &lt;stdio.h&gt;
  62. char *fgets(char *restrict <var>buf</var>, int <var>n</var>, FILE *restrict <var>fp</var>);
  63. #define _GNU_SOURCE
  64. #include &lt;stdio.h&gt;
  65. char *fgets_unlocked(char *restrict <var>buf</var>, int <var>n</var>, FILE *restrict <var>fp</var>);
  66. #include &lt;stdio.h&gt;
  67. char *_fgets_r(struct _reent *<var>ptr</var>, char *restrict <var>buf</var>, int <var>n</var>, FILE *restrict <var>fp</var>);
  68. #include &lt;stdio.h&gt;
  69. char *_fgets_unlocked_r(struct _reent *<var>ptr</var>, char *restrict <var>buf</var>, int <var>n</var>, FILE *restrict <var>fp</var>);
  70. </pre></div>
  71. <p><strong>Description</strong><br>
  72. Reads at most <var>n-1</var> characters from <var>fp</var> until a newline
  73. is found. The characters including to the newline are stored
  74. in <var>buf</var>. The buffer is terminated with a 0.
  75. </p>
  76. <p><code>fgets_unlocked</code> is a non-thread-safe version of <code>fgets</code>.
  77. <code>fgets_unlocked</code> may only safely be used within a scope
  78. protected by flockfile() (or ftrylockfile()) and funlockfile(). This
  79. function may safely be used in a multi-threaded program if and only
  80. if they are called while the invoking thread owns the (FILE *)
  81. object, as is the case after a successful call to the flockfile() or
  82. ftrylockfile() functions. If threads are disabled, then
  83. <code>fgets_unlocked</code> is equivalent to <code>fgets</code>.
  84. </p>
  85. <p>The functions <code>_fgets_r</code> and <code>_fgets_unlocked_r</code> are simply
  86. reentrant versions that are passed the additional reentrant structure
  87. pointer argument: <var>ptr</var>.
  88. </p>
  89. <br>
  90. <p><strong>Returns</strong><br>
  91. <code>fgets</code> returns the buffer passed to it, with the data
  92. filled in. If end of file occurs with some data already
  93. accumulated, the data is returned with no other indication. If
  94. no data are read, NULL is returned instead.
  95. </p>
  96. <br>
  97. <p><strong>Portability</strong><br>
  98. <code>fgets</code> should replace all uses of <code>gets</code>. Note however
  99. that <code>fgets</code> returns all of the data, while <code>gets</code> removes
  100. the trailing newline (with no indication that it has done so.)
  101. </p>
  102. <p><code>fgets_unlocked</code> is a GNU extension.
  103. </p>
  104. <p>Supporting OS subroutines required: <code>close</code>, <code>fstat</code>, <code>isatty</code>,
  105. <code>lseek</code>, <code>read</code>, <code>sbrk</code>, <code>write</code>.
  106. </p>
  107. <br>
  108. <hr>
  109. <div class="header">
  110. <p>
  111. Next: <a href="fgetwc.html#fgetwc" accesskey="n" rel="next">fgetwc</a>, Previous: <a href="fgetpos.html#fgetpos" accesskey="p" rel="prev">fgetpos</a>, Up: <a href="Stdio.html#Stdio" accesskey="u" rel="up">Stdio</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  112. </div>
  113. </body>
  114. </html>