Beginner Question

This is a discussion on Beginner Question within the C Programming forums, part of the General Programming Boards category; Hi guys, I'm currently learning C, and I've been following this online guide. I've gotten up to one of the ...

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230

    Beginner Question

    Hi guys, I'm currently learning C, and I've been following this online guide. I've gotten up to one of the many (Try This!) bubbles, and I'm stuck as to what it really means.

    It reads: "Create an array of records and write some code to sort that array on one integer field."

    I understand a bit about arrays and how they work, but I'm not quiet sure what it means by 'an array of records'. Not sure what records are, as it has no mention so far in the guide. Another thing, 'write some code to sort that array on one integer field', what does it mean by integer field.

    Thanks!
    Last edited by pobri19; 05-03-2008 at 12:24 AM.

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by pobri19 View Post
    I understand a bit about arrays and how they work, but I'm not quiet sure what it means by 'an array of records'. Not sure what records are, as it has no mention so far in the guide. Another thing, 'write some code to sort that array on one integer field', what does it mean by integer field.
    Thanks!
    Jack Black 1000532 12/12/1970

    ^ An example of a record. Lets call this [first name][last name][id][birthdate]. The [id] is a number field, right? So it would be the most logical integer to use as a sorting key. Though, since you and I are not machines, typically when displaying for human consumption, the name is a better choice when it comes to sorting. But hopefully this gets you off the ground.

  3. #3
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230
    Yep, I understand now, thanks!

  4. #4
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230
    Ok so I think it might be reffering to something else, not an actual record as you've posted above. Because in the code just before the example it says something about 'struct rec r;' and has something like:

    Code:
    struct rec
    {
    int a,b,c;
    float d,e,f;
    } r;
    So maybe it's reffering to something else? I really am confused here lol.

    It also says "struct rec r[50]; /* Array of records*/

    So yeah.. No idea what it's talking about.
    Last edited by pobri19; 05-03-2008 at 12:24 AM.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by pobri19 View Post
    Ok so I think it might be reffering to something else, not an actual record as you've posted above. Because in the code just before the example it says something about 'struct rec r;' and has something like:

    Code:
    struct rec
    {
    int a,b,c;
    float d,e,f;
    } r;
    So maybe it's reffering to something else? I really am confused here lol.

    It also says "struct rec r[50]; /* Array of records*/

    So yeah.. No idea what it's talking about.
    Before you can create an array of records, you have to tell the compiler what your record consists of.

    In the "struct rec" part, you defined what each "rec" will contain. Then with that last trailing "r", you said that the variable "r" is an instance of rec, from now on.


    The "struct rec r[50] says that you want an array of 50 (0 - 49), r's. Since the compiler already knows what "r" is, the "struct rec" part is redundant. Just r[50] would have been enough.

    User defined records like this, are extremely useful since they can be used to gather all the data about "something" together, and have it all handy to work with.

  6. #6
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    Since the compiler already knows what "r" is, the "struct rec" part is redundant
    no it is not... it is like to say
    Code:
    int x; /* makes x an int */
    int x[50] ; /* makes x an array of int, but because compiler knows what x is - you can drop the int part */
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner: Linked List question
    By WeatherMan in forum C++ Programming
    Replies: 2
    Last Post: 04-03-2008, 07:16 AM
  2. Quick IF statement question (beginner)
    By jim.rattlehead in forum C Programming
    Replies: 23
    Last Post: 11-29-2007, 05:51 AM
  3. beginner question
    By Barrot in forum C++ Programming
    Replies: 4
    Last Post: 08-19-2005, 02:17 PM
  4. Question About External Files (Beginner)
    By jamez05 in forum C Programming
    Replies: 0
    Last Post: 08-11-2005, 07:05 AM
  5. Beginner on Win32 apps, lame question.
    By Templario in forum C Programming
    Replies: 3
    Last Post: 11-06-2002, 07:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21