PDA

View Full Version : Problem with naming a queue


joeserhal
03-22-2008, 05:33 AM
Hi there,
I'm facing some trouble with creating and naming queues in C language.
I need to create five queues using a "for" loop, and with each iteration of the "for" loop, a created queue will be given a name depending on the index of the iteration. It should look like something like this:

for(i=0;i<5;i++)
{
q(i) = CreateQueue(size 2);
}

At the first iteration, I should get a queue called q0 or something, then q1....

I need this because, at a later stage in my program, i need to access,through a "for" loop, a particular queue depending on the index of the iteration.

Does anybody know how i can do this??....
Thanks

Spookster
03-22-2008, 08:14 AM
You shouldn't try to design a program by coding it. Design it first and worry about coding later.

What is CreateQueue returning? A pointer to whatever you have defined to be a queue I would presume? I would also venture to guess that your queue is a struct? So you should be returning a pointer to some structure you have defined that represents your queue. So just declare and array of pointers and call it queue. Call your CreateQueue in your loop and assign the pointers to your pointer array.