简体   繁体   中英

calling C main from Objectivec

I want to call a C classes main function from within another class (which is written with objectiveC). I would like to pass some arguments to the main. I tried it like this, but the frist parameter gets ignored:

char *argv[] = 
{ 
    "--a", 
    "--b", 
    srcFile , 
    destFile
};
my_c_main(4, argv);

Am I doing something wrong?

the first entry in the argv array is the application name itself. so if you want to pass arguments, skip the first entry and start your args at the second entry in the array. you could probably just use an empty string as the first array element.

char *argv[] = 
{
    "", 
    "--a", 
    "--b", 
    srcFile , 
    destFile
};
my_c_main(5, argv);

main的第一个参数是程序名称本身,因此您需要一个由5个参数组成的数组。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM