-
beginners help
how do i go about sorting a file in order. The file will contain three different sized structures. The sort will be of the second field, the first denoting which type of structure the record is. The question says to "define the three structures, use a standard sort utillity and is quite straightforward." I have done a sort of an array, comparing elements and if need be swap them. Do i do this with a file, if so why does the question say to output to a new "sorted file"?
-
Didn't you post the exact same question the other day?
As I told you use qsort() to sort. If they are strings you can compare them lexicographically with strcmp() or strncmp()
For sorting your file I would expect you to read the data in to memory and make the required changes then rewrite it to disk again.
You have had a couple of days so where is your attempt at this?
Lets see some code if you want real help!
-
HI another compu-teach-yourself student, it looks like your at the same stage as i am (((i think))))this may be what your looking for
as you will see there are a few of us here(jebus save us!)
-
Stage 4. Program 2 "straightforward" ? It would be if you have been on the 2 day course to teach the solutions to this little teaser. Got thru to a tutor a last, said the same as you have, and i should recieve my invite shortly???? Thx for the pointers it'll give me something to read upon
-
Hi, you really should have attended dudley before now. Program 2 is hard to get to grips with if you haven't done the prep course.
here goes....
open files - validated file, new sorted file and printer.
read val file to get number of records on file
use malloc to allocate memory for number of records
sort records now in memory in cust code order then
sort records again so create record not followed by any other record
write sorted records to sorted file
close sorted file and re-open to read mode
read sorted file and send to printer
close all files.
if your 1st program produced a text file to get number of records on file you will have to read all records to get number of records.
if your 1st program produced a binary file use fseek(); and ftell(); to get number of records.
I havenot told you anything here you would not have got down at dudley.
-
Cheers, been 5 weeks since i sent a draft of prog 1. Still no date "your work is being actioned" At least i can give it a try. Give me a rest from prog 3? Thx.