1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
<html lang="en">
<head>
<title>Line-Oriented Input - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.11">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="C_002dStyle-I_002fO-Functions.html#C_002dStyle-I_002fO-Functions" title="C-Style I/O Functions">
<link rel="prev" href="Simple-Output.html#Simple-Output" title="Simple Output">
<link rel="next" href="Formatted-Output.html#Formatted-Output" title="Formatted Output">
<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">
<p>
<a name="Line-Oriented-Input"></a>
<a name="Line_002dOriented-Input"></a>
Next: <a rel="next" accesskey="n" href="Formatted-Output.html#Formatted-Output">Formatted Output</a>,
Previous: <a rel="previous" accesskey="p" href="Simple-Output.html#Simple-Output">Simple Output</a>,
Up: <a rel="up" accesskey="u" href="C_002dStyle-I_002fO-Functions.html#C_002dStyle-I_002fO-Functions">C-Style I/O Functions</a>
<hr>
</div>
<h4 class="subsection">14.2.3 Line-Oriented Input</h4>
<p>To read from a file it must be opened for reading using <code>fopen</code>.
Then a line can be read from the file using <code>fgetl</code> as the following
code illustrates
<pre class="example"> fid = fopen ("free.txt");
txt = fgetl (fid)
-| Free Software is needed for Free Science
fclose (fid);
</pre>
<p class="noindent">This of course assumes that the file ‘<samp><span class="samp">free.txt</span></samp>’ exists and contains
the line ‘<samp><span class="samp">Free Software is needed for Free Science</span></samp>’.
<!-- file-io.cc -->
<p><a name="doc_002dfgetl"></a>
<div class="defun">
— Built-in Function: <b>fgetl</b> (<var>fid, len</var>)<var><a name="index-fgetl-779"></a></var><br>
<blockquote><p>Read characters from a file, stopping after a newline, or EOF,
or <var>len</var> characters have been read. The characters read, excluding
the possible trailing newline, are returned as a string.
<p>If <var>len</var> is omitted, <code>fgetl</code> reads until the next newline
character.
<p>If there are no more characters to read, <code>fgetl</code> returns −1.
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002dfread.html#doc_002dfread">fread</a>, <a href="doc_002dfscanf.html#doc_002dfscanf">fscanf</a>.
</p></blockquote></div>
<!-- file-io.cc -->
<p><a name="doc_002dfgets"></a>
<div class="defun">
— Built-in Function: <b>fgets</b> (<var>fid, len</var>)<var><a name="index-fgets-780"></a></var><br>
<blockquote><p>Read characters from a file, stopping after a newline, or EOF,
or <var>len</var> characters have been read. The characters read, including
the possible trailing newline, are returned as a string.
<p>If <var>len</var> is omitted, <code>fgets</code> reads until the next newline
character.
<p>If there are no more characters to read, <code>fgets</code> returns −1.
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002dfputs.html#doc_002dfputs">fputs</a>, <a href="doc_002dfopen.html#doc_002dfopen">fopen</a>, <a href="doc_002dfread.html#doc_002dfread">fread</a>, <a href="doc_002dfscanf.html#doc_002dfscanf">fscanf</a>.
</p></blockquote></div>
</body></html>
|