getopt.h: Compiling Linux C-Code in Windows

后端 未结 9 1910
梦谈多话
梦谈多话 2020-11-30 02:20

I am trying to get a set of nine *.c files (and nine related *.h files) to compile under Windows.

The code was originally designed in Linux to take command line argu

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 02:58

    From what I remember of getopt.h, all it does is provide a handy parser for processing argv from your main function:

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

    Windows console programs still have a main method, so you can simply loop through your argv array and parse the parameters yourself. e.g.

    for ( int i = 1; i < argc; i++ )
    {
      if (!strcmp(argv[i], "-f"))
        filename = argv[++i];
    }
    

提交回复
热议问题