473,412 Members | 5,385 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Code for lseek

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
Thanx
Jan 12 '06 #1
2 9439
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
Jan 12 '06 #2
Ico
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


I believe lseek() is a POSIX extension, and not a part of standard
ANSI-C. You might want to ask your question at comp.unix.programmers.

By the way, did you even give it a try to find out yourself ?

--
:wq
^X^Cy^K^X^C^C^C^C
Jan 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
9
by: bigoxygen | last post by:
Hi. I'm using a 3 tier FrontController Design for my web application right now. The problem is that I'm finding to have to duplicate a lot of code for similar functions; for example, listing...
4
by: jason | last post by:
Hello. Newbie on SQL and suffering through this. I have two tables created as such: drop table table1; go drop table table2; go
16
by: Dario de Judicibus | last post by:
I'm getting crazy. Look at this code: #include <string.h> #include <stdio.h> #include <iostream.h> using namespace std ; char ini_code = {0xFF, 0xFE} ; char line_sep = {0x20, 0x28} ;
109
by: Andrew Thompson | last post by:
It seems most people get there JS off web sites, which is entirely logical. But it is also a great pity since most of that code is of such poor quality. I was looking through the JS FAQ for any...
5
by: ED | last post by:
I currently have vba code that ranks employees based on their average job time ordered by their region, zone, and job code. I currently have vba code that will cycle through a query and ranks each...
3
by: venkat | last post by:
Hi, I am learing Unix internals. I have come across a problem where i am not able to understand what is happening. As i gone through the book i found that lseek will give the physical descriptor...
3
by: pal | last post by:
Hi, I want to move file pointer to the end of the file through any funciton ( like lseek() ) Could anyone help me out to dothis .
36
by: sh.vipin | last post by:
how to make large macro paste the code as it is Problem Explanation '-- For example in the program below /* a.c - starts here */ #define DECL_VARS() \ unsigned int a0;\ unsigned int a1;\...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.