0

Im practicing threads and i found a problem that says "Create as many threads as arguments receive the program being executed"

I.E = ./program a c d (here 3 threads will be created)

I have no idea how to take the arguments and use it, can you guys teach me how i can to this? im not asking you to make me the code (some people may think im asking you to make my homework and it is not like that) thank you

chrk
  • 4,037
  • 2
  • 39
  • 47
Hook
  • 391
  • 5
  • 16
  • 3
    You need to take a closer look at your `main` function, in particular the meaning of its arguments. – djikay Jul 13 '14 at 18:20
  • 2
    Google argc and argv. – Paul R Jul 13 '14 at 18:22
  • 1
    This post isn't actually about threading. It's more of a basic C question on working with variable length argument arrays. Please trim off the threading stuff from the post. – Paul Sasik Jul 13 '14 at 18:22

1 Answers1

0

Did you ever notice the argc and argv in the prototype of main-

int main(int argc, char* argv[])

Those two variables are responsible for managing the command like arguments. argc or argument count stores the number of arguments received from the command line. One argument is always received which is the program's current directory. argv[] stores the actual arguments received. These are stored as strings in the form of array. To access, say 1st argument, you can use

printf("%s", argv[0]);
Harshil Sharma
  • 2,016
  • 1
  • 29
  • 54
  • 1
    Please note that the argv[0] is always the name of the command line used to execute the program. The first user supplied argument is argv[1]. – Stian Svedenborg Jul 13 '14 at 19:01