Movatterモバイル変換


[0]ホーム

URL:


Logo

User Tools

Site Tools

You are here:start »c »stdio.h »fgetpos

Sidebar

c:stdio.h:fgetpos

fgetpos

intfgetpos(FILE*stream,fpos_t*pos);

Stores current file position for stream stream in *pos. Returns non-zero on error.

Description

The fgetpos() function stores the file position indicator of the given file stream in the given position variable.
The position variable is of type fpos_t (which is defined in stdio.h) and is an object that can hold every possible position in a FILE.
fgetpos() returns zero upon success, and a non-zero value upon failure.

C Sourcecode Example

/*  * fgetpos example code * http://code-reference.com/c/stdio.h/fgetpos */  #include<stdio.h>/* including standard library *///#include <windows.h> /* uncomment this for Windows */  int main(void){FILE*stream;fpos_t file_pos;int c,i; if((stream=fopen("test.txt","r"))==NULL){printf("Cannot open file.\n");return1;} fgetpos(stream,&file_pos);while((c=fgetc(stream))!= EOF){if( c=='#'){fgetpos(stream,&file_pos);} printf("character is:  %c\n", c);} printf("1st Position of # is the %d Byte\n", file_pos);fclose(stream); return0;}

fgetpos example output

  output: ./fgetpos   character is:  L  character is:  i  character is:  n  character is:  e  character is:     character is:  1  character is:    character is:  #  .... and so on  ...  1st Position of # is the 24 Byte

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdio.h/fgetpos.txt · Last modified: 2024/02/16 01:05 (external edit)

Page Tools

Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Share Alike 3.0 Unported
CC Attribution-Share Alike 3.0 UnportedDriven by DokuWiki
Tweet this link
ImpressumDatenschutz


[8]ページ先頭

©2009-2025 Movatter.jp