-1
我在寫一個用戶驗證計劃和SUCESSFUL登錄後,我提供像提示一個shell:基於命令如何分配在ARGC字符串和argv
int main()
{
int argc;
char **argv;
char *username = malloc(50);
char *passwd = malloc(32);
char command[200];
printf("Enter username:");
scanf("%s", username);
printf("\n");
printf("Enter password:");
get_passwd(passwd); //User defined function for taking the password without echoing.
// Then a authentication module is called;
int success = authenticate_user(username, passwd);
//After successful authentication of user I will print like:
printf("test @ %s >", username);
// To look user that he is working on program's own terminal where user can input some command as string
gets(command);
//Here is the main problem
// I tried using strtok() and g_shell_parse_argv() but not getting the desired result.
return 0;
}
其他團隊成員編寫的程序,以採取進一步行動字符串解析。他們表示,我必須將它解析爲像main(int argc,int ** argv)函數簽名形式變量這樣的argc和argv變量。
是否有任何C庫可以做到這一點或任何最佳實踐提示或樣本進行。
最後,我必須解析argc和argv中的字符串。
任何幫助,高度讚賞。 謝謝。
請直接顯示您的研究成果。請先閱讀[問]頁面。 –
'argc'和'argv'是程序運行時由操作系統填充的'main'函數的參數。在你的代碼中,他們是uniniliatised局部變量。你如何期望他們掌握合理的數據?只是將它們命名爲'argc'和'argv'並不會讓它們神奇地引用命令行參數。 –
請注意,'main'的原型是'int main(int argc,char ** argv);'。在你的問題中,你說'int ** argv' –