typedef struct { nat id; char *data; } element_struct; typedef element_struct * element; void push(element e, queue s) { nat lt = s->length; if (lt == max_length - 1) { printf('Error in push: Queue is full.\n'); return; } else { s->contents[lt] = e; s->length = lt + 1; } } int main () { push(something_of_type_element, s); }
How would i go about formatting ‘something_of_type_element‘?
Thanks
Notes: nat is the same as int
Like this:
If you have a C99 compiler you can do this:
Note that the data in the structure must be copied if it needs to live longer than the scope in which it was defined. Otherwise, memory can be allocated on the heap with malloc (see below), or a global or static variable could be used.