strider031598
asked on
Sorting Text
Has anyone writting a program that asks the user for a text file and then the program sorts the
lines alphabetically and saves the result to another file? For example, a sample run of the
program might be:
Enter name of text file to be sorted: C:\filename.txt
Enter name of output file: C:\filename2.txt
Sorted C:\filename.txt and saved to C:\filename2.txt
lines alphabetically and saves the result to another file? For example, a sample run of the
program might be:
Enter name of text file to be sorted: C:\filename.txt
Enter name of output file: C:\filename2.txt
Sorted C:\filename.txt and saved to C:\filename2.txt
Is this a homework assignment?
ASKER
vshina: yes, I would like a source code.
nietod: no, it's not a homework assignment. I need a quick program that will
sort text alphabetically (I'm writing my collection of CDs on a .txt file).
nietod: no, it's not a homework assignment. I need a quick program that will
sort text alphabetically (I'm writing my collection of CDs on a .txt file).
Simple way: go to DOS prompt, say:
type unsorted.txt | sort > sorted.txt
If you insist on a program: RTFM on qsort.
type unsorted.txt | sort > sorted.txt
If you insist on a program: RTFM on qsort.
ASKER
What's RTFM on qsort?
Simple solution is mentioned above:
sort < usorted.txt > sorted.txt
where sort is the standard DOS sort filter.
Try 'help sort' or sort /? on your system at the DOS prompt.
The mks toolkit has a better sort filter if necessary.
The unix sort is at least as good as the mks one.
RTFM = READ THE (bleeped out) MANUAL
To write a program in C or any of it's derivatives to do this
use C's qsort function call, well documented in any standard
manual or on the MAN pages of any UNIX style system. It is also in the standard on-line help of the DOS/WINxxx run time packages.
If you want to implement the quicksort (qsort) algorithm yourself, I highly recommend Knuth's "Sorting and Searching", Volume III of "The Art of Computer Programming", which covers the theory in detail.
sort < usorted.txt > sorted.txt
where sort is the standard DOS sort filter.
Try 'help sort' or sort /? on your system at the DOS prompt.
The mks toolkit has a better sort filter if necessary.
The unix sort is at least as good as the mks one.
RTFM = READ THE (bleeped out) MANUAL
To write a program in C or any of it's derivatives to do this
use C's qsort function call, well documented in any standard
manual or on the MAN pages of any UNIX style system. It is also in the standard on-line help of the DOS/WINxxx run time packages.
If you want to implement the quicksort (qsort) algorithm yourself, I highly recommend Knuth's "Sorting and Searching", Volume III of "The Art of Computer Programming", which covers the theory in detail.
ASKER
Does anyone have the source to this program?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I have implemented it by reding the text a line at a time and inserting them into a linked list.
However most Operating Systems have a very powerful sort utility which may be easier to use than writing a program.
Do you want a more detailied algorithm or source-code?