I was writing a user validation program and after sucessful login I am providing a shell like prompt:
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;
}
Other team members written program for further action based on the command string parsing. They conveyed that I have to some how parse it into argc and argv variable like in main(int argc, int **argv) function signatures formal variable.
Is there any C library to do that or any best practice hint or sample to proceed.
Finally I have to parse a string in argc and argv.
Any help is highly appreciated. Thanks.