![]() |
C++ file sorting
Can somebody give me an idea how to start doing this??
Tasks: 1. There is one input file which contains a list of data with a number of columns and rows. 2. The file should be sorted according to different column(ranks, location...) depending on the input of the user. My problem is that how should i read the rows so that it can be stored it in a structure, such that the file can be sorted according to one column at a time(e.g. according to the rank). Should spaces be taken into consideration while reading the file?? thanks in advance for any help would be appreciated! |
Re: C++ file sorting
Perhaps you could read the file line by line, and then split the string and store each value into and array, this way you can then access each value and say store it into an array for each coloumn. Checking for white space is a good way to know where to split your string. This may be helpful to you as to how you can cut the string. Also combine this with white space checking and you should have a solution to your problem.
Chris |
Re: C++ file sorting
Like Chris said, you basically need to decide on a delimiting character to separate your columns. You could use a comma, which is fairly common. This of course means that none of your values can contain a comma (or whatever character you choose) unless you provide another marker to escape that value, which then makes the marker invalid unless you have a sequence to add it (think of how escaping with \ works; you can probably just use that, really).
|
Re: C++ file sorting
How is the file laid out? Are the columns padded with spaces or tabs to line up nicely for a human reader, or is there some other delimiter used? Is the file even plain text, or is it a binary file made up of fixed-size records?
If it's a plain text file, perhaps you could post a small piece (half a dozen lines or so) of it here inside [code] [/code] tags to preserve the formatting, and we can offer more helpful suggestions. |
Re: C++ file sorting
thanks again!!
here is how the file is laid out :
World Rank Institution Region Regional Rank Country National Rank Score on Alumni Score on Award Score on HiCi Score on N&S Score on SCI Score on Size Total Score |
Re: C++ file sorting
here is a start. it copies standard input into a vector, sorts it, then copies the vector to standard output. this just uses a lexicographical string comparison.
:
|
| All times are GMT -5. The time now is 4:23 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC