# Beginner Question

• 05-02-2008
pobri19
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!
• 05-02-2008
master5001
Quote:

Originally Posted by pobri19
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.
• 05-02-2008
pobri19
Yep, I understand now, thanks!
• 05-02-2008
pobri19
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.
• 05-03-2008
Quote:

Originally Posted by pobri19
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.
• 05-03-2008
vart
Quote:

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 */```