Fseek

Fseek

fseek is a C function belonging to the ANSI C standard library, and included in the file stdio.h. Its purpose is to change the file position indicator for the specified stream. Because fseek uses 32 bit values on many platforms it has a limitation of maximum 2 gigabyte seeks [http://www.codeproject.com/file/64-bit_fileio.asp] .

Function prototype

:int fseek(FILE "*stream_pointer", long "offset", int "origin");

Argument meaning:
* "stream_pointer" is a pointer to the stream "FILE" structure of which the position indicator should be changed;
* "offset" is a "long" integer which specifies the number of bytes from "origin" where the position indicator should be placed;
* "origin" is an integer which specifies the origin position. It can be:
**SEEK_SET : origin is the start of the stream ;
**SEEK_CUR : origin is the current position ;
**SEEK_END : origin is the end of the stream ;

Return value

The return value is an "integer" which mean:
* "0" (zero) : function performed successfully in the stream
* "nonzero" : an error occurred
* On devices incapable of seeking, the return value is undefined.

Notes that each error number has a distinct meaning. The meaning can be revealed by checking "errno.h".

Example


#include

int main(int argc, char **argv) { FILE *file_pointer; file_pointer = fopen("text.txt","r"); if(fseek(file_pointer, 0, SEEK_SET)) { puts("An error occurred"); } else { char buffer [100] ; fgets(buffer, 100, file_pointer); puts("The first line of the file is:"); puts(buffer); } fclose(file_pointer); return 0;}This program code opens a file called "text.txt" in read-only mode, tries to force the file pointer to the beginning of the file, and outputs the first line of the file.


Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • Stdio.h — Стандартная библиотека языка программирования С assert.h complex.h ctype.h errno.h fenv.h float.h inttypes.h iso646.h limits.h locale.h math.h setjmp.h signal.h stdarg.h stdbool.h stddef.h stdint.h stdio.h stdlib.h …   Википедия

  • stdio.h — Стандартная библиотека языка программирования С assert.h complex.h ctype.h errno.h fenv.h float.h inttypes.h iso646.h limits.h locale.h math.h setjmp.h signal.h stdarg.h stdbool.h stddef.h …   Википедия

  • C file input/output — C Standard Library Data types Character classification Strings Mathematics File input/output Date/time Localiza …   Wikipedia

  • Stdio.h — Saltar a navegación, búsqueda stdio.h, que significa standard input output header (cabecera estandar E/S), es la biblioteca estándar del lenguaje de programación C, el archivo de cabecera que contiene las definiciones de macros, las constantes,… …   Wikipedia Español

  • stdio.h — stdio.h, que significa standard input output header (cabecera estandar E/S), es la biblioteca estándar del lenguaje de programación C, el archivo de cabecera que contiene las definiciones de macros, las constantes, las declaraciones de funciones… …   Wikipedia Español

  • Obfuscated code — Obfuscated code is source or machine code that has been made difficult to understand for humans. Programmers may deliberately obfuscate code to conceal its purpose (security through obscurity) or its logic to prevent… …   Wikipedia

  • Large file support — Large file support, often abbreviated to LFS, is the term frequently applied to the ability to create files larger than 2 GiB on 32 bit operating systems. Rationale Traditionally, many operating systems and their underlying file system… …   Wikipedia

  • StrangeSearch — Infobox Software name = StrangeSearch caption = developer = Jeremy Davis, Dan Dunham latest release version = latest release date = operating system = Windows genre = Search engine license = GNU General Public License website =… …   Wikipedia

  • List of C functions — This page aims to alphabetically list all the predefined functions used in the C standard library, and a few of the non standard functions. * assert.h ** (no functions) * ctype.h ** (non standard) digittoint ** isalnum ** isalpha ** (non… …   Wikipedia

  • SpartaDOS X — Infobox OS name = SpartaDOS X caption = SpartaDOS X command prompt. Taken from the current beta version. developer = ICD, Inc. (4.0 4.21) FTe (4.22) DLT (4.3 4.4) source model = Closed source kernel type = supported platforms = Atari 8 bit family …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”