Computer Science Canada About Structures and Nested Arrays |
Author: | ahsonmonis [ Thu Oct 22, 2009 12:38 am ] |
Post subject: | About Structures and Nested Arrays |
struct event schedule[] = {{{9,45},{9,55}},{{13,0},{14,20}},{{15,0},{16,30}}}; So how can I read each individual entry? I want to use this and compare it to an integer. So basically lets say i have h = 9, I want to see if h>9 or h<9 and h>13 or h<14 and h>15 or h<16 but i cant access the numbers in the schedule array because it is an array of arrays. How can I see what the first element is, the second element etc. |
Author: | OneOffDriveByPoster [ Thu Oct 22, 2009 12:23 pm ] | ||||||
Post subject: | Re: About Structures and Nested Arrays | ||||||
First, some formatting:
Then, it may help if you provided a declaration of struct event.
Then, you can try something like:
|
Author: | ahsonmonis [ Thu Oct 22, 2009 6:43 pm ] | ||||||
Post subject: | Re: About Structures and Nested Arrays | ||||||
I tried it but gave errors.
Ok purpose: Print the first entry and then print the second last entry. So output be like 9, 16 How can I do that.
It is still giving me an error. I attached the programs as well. |
Author: | ahsonmonis [ Thu Oct 22, 2009 6:44 pm ] |
Post subject: | Re: About Structures and Nested Arrays |
oh also, how do u add code tags so it is properly formatted and colored. |
Author: | OneOffDriveByPoster [ Thu Oct 22, 2009 10:08 pm ] | ||||
Post subject: | Re: About Structures and Nested Arrays | ||||
ahsonmonis @ Thu Oct 22, 2009 6:44 pm wrote: oh also, how do u add code tags so it is properly formatted and colored. You can see how by clicking on the "quote" button on the top-right corner of a post that has that. It will only get you the colour though. Space it yourself, or dump it in something that will auto-format first.
Anyhow, when I said to provide a declaration, I meant to the forum. The code I gave was only an example. You do have a declaration in your code already. To access a struct member correctly, it is necessary to know how the struct type was declared. Your relevant declarations are:
So you can refer to the `9' like so:
|
Author: | AtoZ [ Fri Oct 23, 2009 3:37 am ] |
Post subject: | Re: About Structures and Nested Arrays |
Thanks alot. That is exactly what I was looking for. |