Linux中main函數參數詳解

Linux中main函數參數詳解

常用參數

  常用參數有argc和argv,其中argv是程序後面的字符串,argc是第幾個字符串。 man argc得出

       argc  The number of arguments to tclsh or wish.

       argv  Tcl list of arguments to tclsh or wish.

常用函數

  • getopt是對參數進行解析的函數
opt = getopt(argc,argv,"t:w:q:")//將獲取的參數賦值給opt

  • strtoul,將字符串強制轉化
unsigned long int strtoul(const char *nptr, char **endptr, int base);//原型
strtoul(optarg,NULL,0);//將獲取的字符串轉化爲無符號數

  • optarg,外部變量,選項的參數指針
./a.out -v kk //kk就是optarg

  • optind ,int類型,argv的當前索引值。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章