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

C program To read 1000 bytes at a time from a File

can any one help me to solve this one we need to write a c program,
Consider a file of size 5000 bytes. Open the file and read to a buffer
of size buf[1000];

We have to read 1000 bytes only from the file at a time and after
displaying the file we have to lseek 500 bytes back in the file

And read file from 500 to 1000. we have to read this type upto end of
file .
Rgds

Ramesh

May 3 '06 #1
3 4082
you have written the algorithm exactly as you want it .. what is
preventing you from coding it yourself ?

May 3 '06 #2
ramesh wrote:
can any one help me to solve this one we need to write a c program,
Consider a file of size 5000 bytes. Open the file and read to a buffer
of size buf[1000];

We have to read 1000 bytes only from the file at a time and after
displaying the file we have to lseek 500 bytes back in the file

And read file from 500 to 1000. we have to read this type upto end of
file .

What have you tried?

You should be able to do this with standard IO functions (fopen, fread,
fseek).

--
Ian Collins.
May 3 '06 #3

"ramesh" <ra*******@gmail.com> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
can any one help me to solve this one we need to write a c program,
Consider a file of size 5000 bytes. Open the file and read to a buffer
of size buf[1000];

We have to read 1000 bytes only from the file at a time and after
displaying the file we have to lseek 500 bytes back in the file

And read file from 500 to 1000. we have to read this type upto end of
file .


suggestion: read only 500 bytes at a time. It will eliminate an lseek.

?type? buf[1000];
?type? buf2[500];

fread() 500 using into buf2[] /* buf2 has 0-500 */
memcpy() buf2[] into buf[0] /* buf has 0-500 */
fread() 500 using into buf2[] /* buf2 has 500-100 */
memcpy() buf2[] into buf[500] /* buf has 0-500 and 500-1000 */
display 1000 bytes of buf[];
process 500 bytes of buf2[]; /* buf2 still has bytes 500-1000 */
loop & process 500 bytes of buf2[]; /* bytes 1000+, 500 at a time */
Rod Pemberton
May 4 '06 #4

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

Similar topics

1
by: cnu | last post by:
My program generates a log file for every event that happens in the program. So, I open the file and keep it open till the end. This is how I open the file for writing: <CODE> public...
6
by: Alexander Hunziker | last post by:
Hello group, I have a program that reads data from a binary file. I know that at some known position in the file there are 12 4 bytes long floating point numbers. Here's how I read them now: ...
1
by: Phil396 | last post by:
I have to create a simple program but I want it to look as professional as possible. The program needs to open a file on a network share write the contents of a number of files to one file. The...
2
by: JBudge | last post by:
I've created a program that will create zips and exes of all the product downloads on our website (mostly clipart and PowerPoint templates, around 6000 total), but the program slows down...
8
by: paraidy | last post by:
Hi all, as from object i need to read all byte from a file example c: \myphoto.jpg and recreate the file with another name to another directory c:\photo\recreatedphoto.jpg can someone write a...
3
by: nik | last post by:
Hi, I need to read a 9 byte response from a device on the serial port. read in characters at a time. If I do: serialport.read(4) I would get 8 bytes, and if I did serialport.read(5) I think...
4
by: Farooqui | last post by:
Hi, I need help in writing a VB6 program to read 1000 word documents and extract my required information into a .dbf file. All word documents are having different information in a tabular form...
0
by: OlgaGor | last post by:
How can I read header of grafic file if file stored in DataBase like array of bytes. I must known which type was in grafic file before store in DB. Thank/
4
by: Waqas Danish | last post by:
Hello, I am using standard socket functions to send and receive data on a client/server model. I am using K-Develop under Ubuntu 10.04 OS. The application works fine locally but when I deploy it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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.