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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
<html lang="en">
<head>
<title>File Positioning - 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="EOF-and-Errors.html#EOF-and-Errors" title="EOF and Errors">
<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="File-Positioning"></a>
Previous: <a rel="previous" accesskey="p" href="EOF-and-Errors.html#EOF-and-Errors">EOF and Errors</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.19 File Positioning</h4>
<p>Three functions are available for setting and determining the position of
the file pointer for a given file.
<!-- file-io.cc -->
<p><a name="doc_002dftell"></a>
<div class="defun">
— Built-in Function: <b>ftell</b> (<var>fid</var>)<var><a name="index-ftell-809"></a></var><br>
<blockquote><p>Return the position of the file pointer as the number of characters
from the beginning of the file <var>fid</var>.
<!-- 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_002dfseek.html#doc_002dfseek">fseek</a>, <a href="doc_002dfopen.html#doc_002dfopen">fopen</a>, <a href="doc_002dfclose.html#doc_002dfclose">fclose</a>.
</p></blockquote></div>
<!-- file-io.cc -->
<p><a name="doc_002dfseek"></a>
<div class="defun">
— Built-in Function: <b>fseek</b> (<var>fid, offset, origin</var>)<var><a name="index-fseek-810"></a></var><br>
<blockquote><p>Set the file pointer to any location within the file <var>fid</var>.
<p>The pointer is positioned <var>offset</var> characters from the <var>origin</var>,
which may be one of the predefined variables <code>SEEK_CUR</code><!-- /@w --> (current
position), <code>SEEK_SET</code><!-- /@w --> (beginning), or <code>SEEK_END</code><!-- /@w --> (end of
file) or strings "cof", "bof" or "eof". If <var>origin</var> is omitted,
<code>SEEK_SET</code><!-- /@w --> is assumed. The offset must be zero, or a value returned
by <code>ftell</code> (in which case <var>origin</var> must be <code>SEEK_SET</code><!-- /@w -->).
<p>Return 0 on success and -1 on error.
<!-- 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_002dftell.html#doc_002dftell">ftell</a>, <a href="doc_002dfopen.html#doc_002dfopen">fopen</a>, <a href="doc_002dfclose.html#doc_002dfclose">fclose</a>.
</p></blockquote></div>
<!-- file-io.cc -->
<p><a name="doc_002dSEEK_005fSET"></a>
<div class="defun">
— Built-in Function: <b>SEEK_SET</b> ()<var><a name="index-SEEK_005fSET-811"></a></var><br>
— Built-in Function: <b>SEEK_CUR</b> ()<var><a name="index-SEEK_005fCUR-812"></a></var><br>
— Built-in Function: <b>SEEK_END</b> ()<var><a name="index-SEEK_005fEND-813"></a></var><br>
<blockquote><p>Return the value required to request that <code>fseek</code> perform
one of the following actions:
<dl>
<dt><code>SEEK_SET</code><dd>Position file relative to the beginning.
<br><dt><code>SEEK_CUR</code><dd>Position file relative to the current position.
<br><dt><code>SEEK_END</code><dd>Position file relative to the end.
</dl>
</p></blockquote></div>
<!-- file-io.cc -->
<p><a name="doc_002dfrewind"></a>
<div class="defun">
— Built-in Function: <b>frewind</b> (<var>fid</var>)<var><a name="index-frewind-814"></a></var><br>
<blockquote><p>Move the file pointer to the beginning of the file <var>fid</var>, returning
0 for success, and -1 if an error was encountered. It is equivalent to
<code>fseek (</code><var>fid</var><code>, 0, SEEK_SET)</code>.
</p></blockquote></div>
<p>The following example stores the current file position in the variable
<code>marker</code>, moves the pointer to the beginning of the file, reads
four characters, and then returns to the original position.
<pre class="example"> marker = ftell (myfile);
frewind (myfile);
fourch = fgets (myfile, 4);
fseek (myfile, marker, SEEK_SET);
</pre>
<!-- DO NOT EDIT! Generated automatically by munge-texi. -->
<!-- Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, -->
<!-- 2006, 2007, 2008, 2009 John W. Eaton -->
<!-- This file is part of Octave. -->
<!-- Octave is free software; you can redistribute it and/or modify it -->
<!-- under the terms of the GNU General Public License as published by the -->
<!-- Free Software Foundation; either version 3 of the License, or (at -->
<!-- your option) any later version. -->
<!-- Octave is distributed in the hope that it will be useful, but WITHOUT -->
<!-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -->
<!-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -->
<!-- for more details. -->
<!-- You should have received a copy of the GNU General Public License -->
<!-- along with Octave; see the file COPYING. If not, see -->
<!-- <http://www.gnu.org/licenses/>. -->
</body></html>
|