473,326 Members | 2,813 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,326 software developers and data experts.

read in file offset

Hiya,

Im working on a project to read in a file (its a bitmap, but thats
irrelevant) and I want to read in all the data after an offset, ive
tried using -

fread(bitmap_buffer, offset, 1, fp);

but this doesnt work and only reads in the value at the offset (0x436h
irrelevant once again i suppose).

so my question is how do i read in all the data AFTER a certain
offset, into my buffer?

any help much appreciated, and no this isnt school work (school terms
out anyway) Im just doing this becuase im learning to program and
starting to enjoy writing programs that can do useful stuff :-)

thanks
Nov 14 '05 #1
3 8352
go*************@hotmail.com (spleen) writes:
so my question is how do i read in all the data AFTER a certain
offset, into my buffer?


See the FAQ on how to determine a file's size.
--
Ben Pfaff
email: bl*@cs.stanford.edu
web: http://benpfaff.org
Nov 14 '05 #2
spleen <go*************@hotmail.com> wrote:
Im working on a project to read in a file (its a bitmap, but thats
irrelevant) and I want to read in all the data after an offset, ive
tried using - fread(bitmap_buffer, offset, 1, fp); but this doesnt work and only reads in the value at the offset (0x436h
irrelevant once again i suppose).


This would read 'offset' bytes at the current position in the file.
You can use the fseek() fucntion to move within the file, i.e. use

fseek( fp, offset, SEEK_SET );

to jump to position 'offset' in the file and then start reading.

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Nov 14 '05 #3

"spleen" <go*************@hotmail.com> wrote

Im working on a project to read in a file (its a bitmap, but thats
irrelevant) and I want to read in all the data after an offset, ive
tried using -

fread(bitmap_buffer, offset, 1, fp);

but this doesnt work and only reads in the value at the offset (0x436h
irrelevant once again i suppose).

so my question is how do i read in all the data AFTER a certain
offset, into my buffer?

The offset for the data (presumably the pixels of the image) is given
somewhere in the header.
That header will probably also contain the image dimensions, and information
that tells you how many bits are stored per pixel.

If you have this information,
1) fseek() to the file position where the pixel data starts.
2) allocate memory with malloc() to hold the pixels
3) fread the whole lot in with one go.

If you don't have the information (eg if the data is compressed)
1) fseek() to the file positon where pixel data starts.
2) call fgetc() to read the data one byte at a time.
3) decode the data, expand your buffer if needed.
4) check for EOF which tells you when the data has finished.
Nov 14 '05 #4

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

Similar topics

4
by: domtam | last post by:
Suppose I have one of those USB storage devices (like a mp3 player, USB thumbdrive, or even digital camera) connected to my computer. I'd like to write a C# program that can - detect that the...
40
by: Abby | last post by:
My .dat file will contain information like below. /////////// First 0x04 0x05 0x06 Second 0x07
2
by: somequestion | last post by:
During copying file , wanna read file Size like this string CheckFileSize(string fileName) { if( fileName == null ) return; FileInfo fi = new FileInfo(fileName); return fi.Length.ToString();...
1
by: potluri040 | last post by:
hi, could any one let me know how to read file thru VB script. Scenerio is like this: i am keeping a personal details such as name, age, sex, company, location in a text file called user details...
1
by: samira | last post by:
hi all, i built aproject to my client he need that the visitors to the site can read file from his computer, how can i do this , we uuse asp.net over c#
3
by: =?Utf-8?B?Sm9obiBXYWxrZXI=?= | last post by:
Hi, Is there anything wrong with the code below in sending my browser page to Excel? Before my page opens in Excel there's a message "Problems came up in the following areas during load:" and it...
2
by: xplode144 | last post by:
I have a Web application. i need to read a file once during the startup and preserve the read data throughout the life of the application. i will to access the data often during the page_load of...
2
by: danimian | last post by:
Hello, first i am creating xml file if file does not exist. String myFile = "C:\myxmlfile.xml"; if (!File.Exists(myFile)) { using (FileStream conStream = new FileStream(myFile,...
0
by: leeamiin | last post by:
Hi, i need help with bellow file format, i work for telecom company and i'm the developer, what i need help with is to read file with bellow format, as you can see the file has { and , as...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.