Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Circular file

Posted on 2006-07-24
3
Medium Priority
?
316 Views
Last Modified: 2013-11-20
Hi everybody,
I need to write a file that i want to limit the size to 800 Kb and when have this size, start to write from the top of the file and
deleting this first line and so on.
How can i do it.

Thanks.
0
Comment
Question by:SalvaThor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Expert Comment

by:reidy_boy
ID: 17177076
Store your data in an array first.  Declare an array of that size in your program.  Write to the array and starting at the beginning when you get to the end.  When you are ready to write the file, just reference the array.
0
 
LVL 2

Accepted Solution

by:
snyp earned 375 total points
ID: 17186047
why not just keep track of how much you've written to the file and then fseek() your file when you hit your limit?

however.. let's say you're at position 0xC7FFF and you want to write 0x1000 bytes.. try the following..
you'll need to know the size of the data you're writing obviously..

#define SIZELIMIT 0xC8000
char dataArray[512];
unsigned long dataSize;
unsigned long writeSize;
unsigned long filePos;

..

filePos = ftell(filePtr);

if (filePos + dataSize >= SIZELIMIT) {

writeSize = dataSize - ((filePos + dataSize) % SIZELIMIT); // write as much as we can up to the end of the 800kb
fwrite(&dataArray[0], writeSize, 1, filePtr);

fteek(filePtr, 0, 0); // back to the start of the file
fwrite(&dataArray[((filePos + dataSize) % SIZELIMIT)], dataSize - writeSize, filePtr); // write the remainder at 0

}

else
fwrite(&dataArray[0], dataSize, 1, filePtr); // data is small enough to fit, just write it all
0
 
LVL 2

Expert Comment

by:snyp
ID: 17186065
i'm sorry, i need to correct the code there..

fseek(filePtr, 0, 0); // back to the start of the file
fwrite(&dataArray[writeSize], dataSize - writeSize, filePtr); // write the remainder at 0
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question