0

I have an assignment which tells me i need to accept arguments from the command line. I know how to accept arguments from the command line, however this is what i need

I am told my arguments are as follows name_of_function name_of_variable argument1, arugment2

is there an easy way to map name_of_function to the name of the function and name_of_variable to the name of the global variable, without going strcmp on each of them ?

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Lena Bru
  • 13,521
  • 11
  • 61
  • 126
  • i can do it with strcmp, but is there any better way? – Lena Bru May 09 '14 at 14:46
  • You have to use the data your read from the user. – this May 09 '14 at 14:47
  • I don't understand your comment. As I said, the user inputs "read_number A,1" and as a result i am supposed to invoke a method called "read_number" and do A=1 in it, is there a good way to map between the function name and the string without doing if else on all the possible variations i have ? if there isnt, just say "Lena, there is no such thing" don't give me cryptic comments – Lena Bru May 09 '14 at 14:52
  • It isn't very clear what are you asking. Take a look at a map container. – this May 09 '14 at 14:54
  • 1
    This isn't avaiable out of the box. For a ice answer on this read here: http://stackoverflow.com/a/6064904/694576 – alk May 09 '14 at 15:30

1 Answers1

1

There is no tool or library that converts a string to the corresponding variable, function, or anything else in C. When you have e.g. a .NET runtime environment you could use reflection to see, if an object is in your program and to access it.

You will have to use strcmp or similar to interpret the command line arguments and decide how to deal with the commands.

harper
  • 13,345
  • 8
  • 56
  • 105