0

I am just learning objective C and got an assignment to wrap C library to invoke via objective C. I am having trouble in passing character pointer array to c function. Basically i am invoking main method of c program via objective c but unable to pass arguments. Below is the function that i am trying to invoke from objective c:

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

where argv is the command line arguments passed from console but now i want to pass those arguments from objective c code. Command line syntax of C program is : ./test -karg1 -larg2 -rarg3....

Please help me how can i invoke it via objective C (for sure i need to learn Pointer in C).

Regards, MP

2
  • “i need to learn Pointer in C” I wrote an article explaining pointers: boredzo.org/pointers Commented Dec 12, 2011 at 0:34
  • Thanks for tutorial. I will definitely read it. Commented Dec 12, 2011 at 8:16

1 Answer 1

1

It is not too hard, and you do not need to know much about pointers:

// Initialize an array of four constant C strings
// (that is, pointers to zero-terminated char arrays)
const char* argv[] = {"./test", "-karg1", "-larg2", "-rarg3"};
// Call your test function
int res = test_main(4, argv);

Note that the initial argument (at position 0) is the name of the program. That is what C programs expect: their first "actual" argument is at position 1.

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

1 Comment

Thanks so much, it worked!!! i tried nearly to it but was not that close. Thanks again now it is working.

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.