Solved

Sorting a binary File

Posted on 2004-10-02
4
240 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
Comment Utility
0
 

Author Comment

by:microcoop
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now