This shows you the differences between two versions of the page.
— |
c:stdio.h:fsetpos [2024/02/16 01:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{keywords>wiki library source code example reference}} | ||
+ | ====== fsetpos ====== | ||
+ | |||
+ | <code c> | ||
+ | int fsetpos(FILE *stream, const fpos_t *pos); | ||
+ | </code> | ||
+ | reset the position indicator to using fsetpos() | ||
+ | stores the current file position indicator to the location indicated by the information in pos | ||
+ | Returns non-zero on error. | ||
+ | ===== C Sourcecode Example ===== | ||
+ | <code c> | ||
+ | #include <stdio.h> /* including standard library */ | ||
+ | //#include <windows.h> /* uncomment this for Windows */ | ||
+ | |||
+ | |||
+ | int main( void ) | ||
+ | { | ||
+ | FILE *stream; | ||
+ | fpos_t file_pos; | ||
+ | int c; | ||
+ | int i; | ||
+ | |||
+ | if((stream=fopen("test.txt","r"))==NULL) { | ||
+ | printf("Cannot open file.\n"); | ||
+ | return 1; | ||
+ | } | ||
+ | |||
+ | fgetpos(stream, &file_pos); | ||
+ | |||
+ | while((c = fgetc(stream) ) != EOF) { | ||
+ | if ( c == '#' ) { | ||
+ | fgetpos(stream, &file_pos); | ||
+ | } | ||
+ | printf("%c", c); | ||
+ | } | ||
+ | |||
+ | printf("1st Position of # is the %d Byte\n", file_pos); | ||
+ | |||
+ | printf("\nset to given position\nand print it again\n"); | ||
+ | fsetpos(stream, &file_pos); | ||
+ | |||
+ | while((c = fgetc(stream) ) != EOF) { | ||
+ | printf("%c", c); | ||
+ | } | ||
+ | |||
+ | fclose(stream); | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ==== output ==== | ||
+ | output: ./fsetpos | ||
+ | test 1234, | ||
+ | ... # ... | ||
+ | this is a test for code-reference.com | ||
+ | 1st Position of # is the 17 Byte | ||
+ | |||
+ | set to given position | ||
+ | and print it again | ||
+ | ... | ||
+ | this is a test for code-reference.com | ||