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 ?

5
  • i can do it with strcmp, but is there any better way? Commented May 9, 2014 at 14:46
  • You have to use the data your read from the user. Commented May 9, 2014 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 Commented May 9, 2014 at 14:52
  • It isn't very clear what are you asking. Take a look at a map container. Commented May 9, 2014 at 14:54
  • 1
    This isn't avaiable out of the box. For a ice answer on this read here: stackoverflow.com/a/6064904/694576 Commented May 9, 2014 at 15:30

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.