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

how to sort the data present in file in ascending or descending order

hi

My application receives daily records, I need to show it sorted if
needed...but I am not finding the right direction to do that...

Dec 1 '05 #1
8 1837
sudhir wrote:
hi

My application receives daily records, I need to show it sorted if
needed...but I am not finding the right direction to do that...


Here's the basic approach...

a) Define a struct type to represent a record of the file

b) Read the file and split each record into the correct struct fields,
storing it in an array (or other data structure) of the structs.

c) Write a comparison function that determines an ordering between two
given records, possibly based on a configurable choice of column
priorities. The function prototype should be
int foo(const void *a, const void *b);
where it takes pointers to the data, and returns -1, 0, or 1 to
signify less, equal or greater respectively.

d) Sort the data using the comparison function. If you chose an array,
you can just use the standard qsort function here.

Let us know if you're having trouble with any of those points, post a
complete and compilable example, and we will be happy to help you further.

--
Simon.
Dec 1 '05 #2
I used c++ and I dare of pointers.. I used classes so I tried it much
better. I sorted the one file using bubble sort but it takes 3
temporary unnecessary files to do so. can u have any better idea.
Thanks

Dec 5 '05 #3
sudhir wrote:

hi

My application receives daily records, I need to show it sorted if
needed...but I am not finding the right direction to do that...


The last time I sorted a file:
I read the whole thing into a linked list.
I sorted the list.
I overwrote the file.

--
pete
Dec 5 '05 #4
sudhir wrote:
I used c++ and I dare of pointers.. I used classes so I tried it much
better. I sorted the one file using bubble sort but it takes 3
temporary unnecessary files to do so. can u have any better idea.
Thanks


Look up the word 'dare'. It does not mean what you think it means.

If you are using C++, then you should be posting in comp.lang.c++

We only discuss C here.

If you would like to implement this in C, then you will be using a
'struct' type instead of a 'class' type. You will find they are similar,
except that they are always public, there is no inheritance, no
constructors or destructors, and no member functions.

I don't understand why you needed any temporary files just to read a
file in, sort it, and write it back out.

--
Simon.
Dec 6 '05 #5
In article <43***********************@news.optusnet.com.au> ,
Simon Biber <ne**@ralmin.cc> wrote:
sudhir wrote:
I used c++ and I dare of pointers.. I used classes so I tried it much
better. I sorted the one file using bubble sort but it takes 3
temporary unnecessary files to do so. can u have any better idea.
Thanks


Look up the word 'dare'. It does not mean what you think it means.


I assume it's another bit of "Indian English". Probably means "am afraid
of" or something like that.

To the OP: Also, while you are at it, look up "dorky 3rd worlder".

Dec 6 '05 #6
Kenny McCormack wrote:
To the OP: Also, while you are at it, look up


Here's another one to look up:

http://www.google.com/search?hl=en&i...ccormack+troll

Results 1 - 10 of about 14,100 for Kenny McCormack troll.

--
pete
Dec 6 '05 #7
pete wrote:

Kenny McCormack wrote:
To the OP: Also, while you are at it, look up
Here's another one to look up:

http://www.google.com/search?hl=en&i...ccormack+troll


I'm sorry. That was the wrong URL:

http://www.google.com/search?hl=en&l...ll&btnG=Search
Results 1 - 10 of about 14,100 for Kenny McCormack troll.


--
pete
Dec 6 '05 #8
In article <43***********@mindspring.com>,
pete <pf*****@mindspring.com> wrote:
Kenny McCormack wrote:
To the OP: Also, while you are at it, look up


Here's another one to look up:

http://www.google.com/search?hl=en&i...ccormack+troll

Results 1 - 10 of about 14,100 for Kenny McCormack troll.


Thank you! Thank you!

I simply must say to you, Mr. Pete: Whatever I'm paying you, it isn't enough!

Dec 6 '05 #9

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

Similar topics

2
by: Ken R. | last post by:
Hello all, I am relatively new to python but I am having an issue with custom sort functions.. I am trying to sort a list of lists or tuples with arbitrary ascending or descending sorts. For...
2
by: Alpay Eno | last post by:
Hello all... I'm using asp to get records from an access database, very similar to the way datagrid would work. The title of each column in my table is a link that alternates the sort order between...
3
by: Petterson Mikael | last post by:
Hi, I have the following package names ( in an xml) that I will transform to html. I need to sort them. <package name="se.company.product.subproduct.boam.fpx.testsignals"> <package...
3
by: happy | last post by:
/* Book name : The prodessional programmers guide to C File name : E:\programs\tc\iti01\ch09\main\01setupm.c Program discription: file setuping -up -Version 01-ver01-W Logic ...
1
by: reiks | last post by:
I have a datatable . My requirement is to sort the table rows in ascending and descending order basing on the columns which I give it. I've used the following expression ...
7
by: DC Gringo | last post by:
I have a datagrid that won't sort. The event handler is firing and return label text, just not the sort. Here's my Sub Page_Load and Sub DataGrid1_SortCommand: -------------------- Private...
4
by: M Harvey | last post by:
I have an arraylist that contains datetime values. What is the best way to sort this arraylist by date ascending? Thanks, Matt
11
by: Alan T | last post by:
Does the ListView supports sort? I want to have a up/down arrow/triangle that show it is sorted asc or desc on the column headers when I click the column header. May be I need a third-party...
15
by: bcochofel | last post by:
Hi, I want to use a variable to sort elements. That var his passed with query string (I'm using Perl CGI to generate XML). Here's a sample of my output:...
0
by: ravikim1 | last post by:
Hi , use Sort::External; $output = '1.txt'; open(FILE, $output); my $sortex = Sort::External->new( mem_threshold => 1024**2 * 1024 ); while (<FILE>) { $sortex->feed($_); # tried to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.