Thread: Array pointers

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    4

    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 .

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    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.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Returning an Array of Pointers to Objects
    By randomalias in forum C++ Programming
    Replies: 4
    Last Post: 04-29-2006, 02:45 PM
  2. two-dimensional dynamic array of pointers to classes
    By Timo002 in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 06:18 AM
  3. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  4. array of pointers to struct array
    By eth0 in forum C++ Programming
    Replies: 1
    Last Post: 01-08-2004, 06:43 PM
  5. array of pointers to structs
    By stumon in forum C Programming
    Replies: 7
    Last Post: 03-24-2003, 07:13 AM