473,770 Members | 2,781 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4116
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*******@gmai l.com> wrote in message
news:11******** *************@u 72g2000cwu.goog legroups.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
6768
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 CLogHandler() { this.m_fsLog = new FileStream(strTodaysLogFile, System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.Read); this.m_swLog = new StreamWriter(this.m_fsLog);
6
17501
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: float temptriangle; fread(&temptriangle, 4, 12, fp);
1
1815
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 files will contain many lines with a carrige return at the end of each line. Each file will have the month and the year in the file name which will be used to determine which files are opened and read. Again the problem sounds simple, but I want...
2
2758
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 dramatically after the first few minutes. The process never gets above 24meg, all child processes called are properly closed when they are done. I've checked the GDI Objects for each process in Task Manager and none of them get above 84 (that process is...
8
2234
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 small example to do it? thx a lot men :)
3
1562
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 the port will block until a time out, since there
4
2620
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 but the following fields are common in all of them: Name, Address, City, Country, Telephone, Mobile, Fax, Email, Title, Remarks I want to extract these fields with their information and append them into my master Address.dbf file
0
979
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
2308
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 on my CentOS 5.5 server, data is not properly received by the server. Whenever client sends more than 1000 bytes, the read() function on server side does not read all the data. Here is the server side code snippet. int sockfd, newsockfd,...
0
9591
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10057
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10002
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9869
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.