diff options
| author | Craig Jennings <c@cjennings.net> | 2025-08-14 22:58:58 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-08-14 22:58:58 -0500 |
| commit | 82ba818ff456bcd6d56a06226e3f27e98fbb55c3 (patch) | |
| tree | 158cfc17b2f644a10f063cb546752cfaae12c97f /devdocs/c/io%2Fftell.html | |
| parent | 9278ddd4ea1a8b1a4c1edaa8894516e3f48d245b (diff) | |
| download | dotemacs-82ba818ff456bcd6d56a06226e3f27e98fbb55c3.tar.gz dotemacs-82ba818ff456bcd6d56a06226e3f27e98fbb55c3.zip | |
removing all downloaded devdocs files
Diffstat (limited to 'devdocs/c/io%2Fftell.html')
| -rw-r--r-- | devdocs/c/io%2Fftell.html | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/devdocs/c/io%2Fftell.html b/devdocs/c/io%2Fftell.html deleted file mode 100644 index c2696fdea..000000000 --- a/devdocs/c/io%2Fftell.html +++ /dev/null @@ -1,77 +0,0 @@ - <h1 id="firstHeading" class="firstHeading">ftell</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><stdio.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl"> <td class="t-dcl-nopad"> <pre data-language="c">long ftell( FILE *stream );</pre> -</td> <td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> </table> <p>Returns the file position indicator for the file stream <code>stream</code>.</p> -<p>If the stream is open in binary mode, the value obtained by this function is the number of bytes from the beginning of the file.</p> -<p>If the stream is open in text mode, the value returned by this function is unspecified and is only meaningful as the input to <code><a href="fseek" title="c/io/fseek">fseek()</a></code>.</p> -<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> stream </td> <td> - </td> <td> file stream to examine </td> -</tr> -</table> <h3 id="Return_value"> Return value</h3> <p>File position indicator on success or <code>-1L</code> if failure occurs.</p> -<p>On error, the <code>errno</code> variable is set to implementation-defined positive value.</p> -<h3 id="Example"> Example</h3> <div class="t-example"> -<p>Demonstrates <code>ftell()</code> with error checking. Writes then reads a few floating-point (FP) values to/from a file.</p> -<div class="c source-c"><pre data-language="c">#include <stdio.h> -#include <stdlib.h> - -/* If the condition is not met then exit the program with error message. */ -void check(_Bool condition, const char* func, int line) -{ - if (condition) - return; - perror(func); - fprintf(stderr, "%s failed in file %s at line # %d\n", func, __FILE__, line - 1); - exit(EXIT_FAILURE); -} - -int main(void) -{ - /* Prepare an array of FP values. */ - #define SIZE 5 - double A[SIZE] = {1.1,2.,3.,4.,5.}; - - /* Write array to a file. */ - const char* fname = "/tmp/test.bin"; - FILE* file = fopen(fname, "wb"); - check(file != NULL, "fopen()", __LINE__); - - const int write_count = fwrite(A, sizeof(double), SIZE, file); - check(write_count == SIZE, "fwrite()", __LINE__); - - fclose(file); - - /* Read the FP values into array B. */ - double B[SIZE]; - file = fopen(fname, "rb"); - check(file != NULL, "fopen()", __LINE__); - - long int pos = ftell(file); /* position indicator at start of file */ - check(pos != -1L, "ftell()", __LINE__); - printf("pos: %ld\n", pos); - - const int read_count = fread(B, sizeof(double), 1, file); /* read one FP value */ - check(read_count == 1, "fread()", __LINE__); - - pos = ftell(file); /* position indicator after reading one FP value */ - check(pos != -1L, "ftell()", __LINE__); - printf("pos: %ld\n", pos); - printf("B[0]: %.1f\n", B[0]); /* print one FP value */ - - return EXIT_SUCCESS; -}</pre></div> <p>Possible output:</p> -<div class="text source-text"><pre data-language="c">pos: 0 -pos: 8 -B[0]: 1.1</pre></div> </div> <h3 id="References"> References</h3> <ul> -<li> C11 standard (ISO/IEC 9899:2011): </li> -<ul><li> 7.21.9.4 The ftell function (p: 337-338) </li></ul> -<li> C99 standard (ISO/IEC 9899:1999): </li> -<ul><li> 7.19.9.4 The ftell function (p: 303-304) </li></ul> -<li> C89/C90 standard (ISO/IEC 9899:1990): </li> -<ul><li> 4.9.9.4 The ftell function </li></ul> -</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="fgetpos" title="c/io/fgetpos"> <span class="t-lines"><span>fgetpos</span></span></a></div> </td> <td> gets the file position indicator <br> <span class="t-mark">(function)</span> </td> -</tr> <tr class="t-dsc"> <td> <div><a href="fseek" title="c/io/fseek"> <span class="t-lines"><span>fseek</span></span></a></div> </td> <td> moves the file position indicator to a specific location in a file <br> <span class="t-mark">(function)</span> </td> -</tr> <tr class="t-dsc"> <td> <div><a href="fsetpos" title="c/io/fsetpos"> <span class="t-lines"><span>fsetpos</span></span></a></div> </td> <td> moves the file position indicator to a specific location in a file <br> <span class="t-mark">(function)</span> </td> -</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/io/c/ftell" title="cpp/io/c/ftell">C++ documentation</a></span> for <code>ftell</code> </td> -</tr> </table> <div class="_attribution"> - <p class="_attribution-p"> - © cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br> - <a href="https://en.cppreference.com/w/c/io/ftell" class="_attribution-link">https://en.cppreference.com/w/c/io/ftell</a> - </p> -</div> |
