Solved

Sorting a binary File

Posted on 2004-10-02
4
243 Views
Last Modified: 2010-04-01
Along the same lines of my other question, I also want to have it do this: I have a program that writes error information to a binary file. Each error code has an ID and alot of other information with it. Since the legacy app shows the error code but not the info, I want to write a command line program that will sort all of the of the information on the ID code and display the contents of the whole file to me sorted.
0
Comment
Question by:microcoop
  • 2
4 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12211435
0
 

Author Comment

by:microcoop
ID: 12211804
I posted both questions, this isn't duplicate the other one is searching but this one is sorting.
0
 
LVL 3

Expert Comment

by:CmdrRickHunter
ID: 12212834
You dont "sort a file," you read in the data from a file, sort it, and display it.

pseudo code:

open the file
read in all the "records" into an array (or other container)
close the file
sort the records by whatever criteria you want
output all the information you want
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 250 total points
ID: 12212851
What you need is an memory index, either if records are fixed- or variable lenght, the index will provide you a fast access to your file, and allow you to sort fastly.
You have 2 alternatives of indexes in mi opinion:
Offset only.- The index array will contain the file position of the init of every record. Every time you want to access a record randomly, go to de index, retrieve offset, and jump into the file, read record data, reading key first.
Offset and key.- The index array will contain also the key or ID of every record, so you don't have to read the file to locate or even sort the file. Once you have located the record by index in the index, then load rest of data into memory, it is more efficient but comsumes more memory, if file is not so bigger, then it is a good alternative.

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

828 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