-
Array pointers
I'd appreciate any help given. I need to store and sort some records; which are composed by various subfields. There is no limitation of the subfields and records. As an example input;
62gDF345 AnDeRs Friden vocalist 3334455
Eh43 JeSPer guitarist swedish
b Raptors11 Bosh
aaaaa Nets33 Kidd 21 1994 March 22
I need to take these inputs, store and sort them(The first subfield of every line is ID and I need to sort them in descending order) . The problem is, I can't take inputs on pointer arrays, since there is no limitation on the number of the lines or subfields. After I take them, I can sort them with strcmp, but I can't take them with neither scanf nor getchar. I'm a newbie to the c and all helps will be welcome .
-
I suppose a really inefficient solution would be to read it line by line, and possibly organize each record as a struct in some way.
From there, you could insert each record into a linked list, or into an array and keep increasing the size of the array if you reach the end.
-
another inefficient solution, which ive mentioned to someone in a thread a while ago, is to read the number of '\n's (newline characters) in the file. this gives you the number of records and you can now make your array of records.
you could do a similar approach on each line to count the number of fields for that record (using a different delimiter, of course).
again, this is an inefficient method and id be interested to see the best way to do it.