On Tue, 15 Apr 2008 16:59:26 -0400, CBFalconer <cb********@yahoo.com>
wrote:
uidzer0 wrote:
I'm attempting to loop through an array of structures passed to
a function, however I'm not sure how to obtain the number of
elements in the array.
The structure is defined as:
typedef struct {
time_t creation_date;
int priority;
char *text;
} note;
And here's the function prototype:
void get_notes(note *notes);
How would I dynamically loop through *notes?
One way is to hold the pointers to note (i.e. the note* items) in
an array terminated with a NULL. Then the function might be:
OP doesn't have an array of pointers, but one pointer to an array.
void get_notes(note *notes) {
while (*notes) {
process_one_note(*notes);
notes++;
}
}
For an array of pointer you need (modulo spacing)
void get_notes (note * * notes)
then as you have it. Or (equivalent to the compiler)
void get_notes (note * notes [] )
to emphasize the array-of-pointer-ness, but downplay the fact that
array parameters/arguments are really pointers; pick your poison.
- formerly david.thompson1 || achar(64) || worldnet.att.net