Hi I am new to C. I'm taking an operating systems class right now and I have a project that requires me to create a set of semaphores. The command line takes in: filename ropt NS value1 value2 value3...valueNS
Where argv0 is the filename
Argv1 is the option to remove the semaphore set (it can also be nopt which means not to remove the set)
Argv2 is the number of semaphores
Argh3 and beyond are the values assigned to the semaphores in the set.
So my question

Is how to I take in a variable number of values from the command line? Let's say that NS is 5...how do I take in 5 values from the command line? I hope I make sense....thanks for any guidance....

Recommended Answers

All 3 Replies

The number of values that will be in argv is exactly argc. When starting the program argc will be equal to the number of elements in argv, meaning that argv[0] through argv[argc-1] are existing cells.

Ok thanks, that makes sense and is very simple...

Glad I could help :) please mark the thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.