I have a big C code I am testing (here is the is the full code if anyone is interested but I will just put the relevant parts: https://github.com/brentmitchell25/EECS-678/blob/master/Lab6/pthreads_pc/producer_consumer.c
It is the producer-consumer problem, now at the start of the main()
function I have the following:
int main (int argc, char *argv[])
{
pthread_t *con;
int cons;
int *concount;
queue *fifo;
int i;
pthread_t *pro;
int *procount;
int pros;
pcdata *thread_args;
/*
* Check the number of arguments and determine the numebr of
* producers and consumers
*/
if (argc != 3) {
printf("Usage: producer_consumer number_of_producers number_of_consumers\n");
exit(0);
}
pros = atoi(argv[1]);
cons = atoi(argv[2]);
//that is not the entire `main()` function I just pasted that part
From my understanding, I should run this and input three numbers: first being the number of arguments argc
, second being the number of producers and third being the number of consumers. However, when I compile then put anything in the command line like ./producer_consumer 3 1 1
(or any other numbers other than the 1s) I get the following:
Usage: producer_consumer number_of_producers number_of_consumers
I think this implies that I should follow this format? but I am not sure if producer_consumer is the program's name or simply another argument I should write.
so my question is: does the code detect argc
itself or do I have to mention it?
note: in my examples I put argc
as 3 as the first entry argv[0]
is reserved for the program's name from my understanding