In article <dq**********@ss405.t-com.hr>, Elephant <Fi*****@hotmail.com> wrote:
I know what lseek does, but i need an example with simple positioning and
reading the file after positioning for 5 bytes from the beggining(the whole
code) not a line like : lseek(........) and what is it for. If anyone have
some simple code for example I 'd be greatfull
lseek() is not part of the C standard; you should ask in a Unix/POSIX
newsgroup for lseek() details.
The standard C equivilent is fseek(). Here's an example.
#include <stdio.h>
#include <stdlib.h>
int main(void) {
long int offset = 5L;
int inputchar;
FILE *inputfile = fopen( "filename.dat", "rb" );
if (inputfile == NULL) {
perror( "file open failed" );
exit(EXIT_FAILURE);
}
if ( fseek( inputfile, offset, SEEK_SET ) != 0 ) {
perror( "fseek failed" );
exit(EXIT_FAILURE);
}
inputchar = fgetc( inputfile );
if ( inputchar == EOF ) {
fprintf( stderr, "End of file while reading at offset %ld\n", offset );
exit(EXIT_FAILURE);
}
printf( "The character at location %ld had value 0x%X\n",
offset, (unsigned int) inputchar );
return 0;
}
--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson