bigtamscot
Programmer
Hi,
I have reached the stage in learning where I have come across Command Line arguments in main ( ). I can write the coding but donot know how to invoke the command line arguments for the program ?????? The truth is I wouldn't know where to start. Operating system is Windows 98, compiler is DevC++. Below is a sample program for password where the users password is passed to main in command line arguments. The program compiles and runs ok (without command entries). But how do I enter a password, e.g. Command Line argument. Every time I run the program I get message incorrect number of parameters, follow program name with parameters. HOW do I do this.
#include <stdio.h>
#include <string.h>
int main (int argc, char *argv [])
{
char password [20] = " c0mmander21 " ;
int fin;
printf(" Logon in Progress \n "
;
if(argc!= 2)
{
printf("Incorrect number of parameters \n"
"Follow program name with parameters \n "
;
return ;
}
if(!strcmp(password, argv[1]))
printf("Logon Complete..."
;
else
{
printf("Incorrect Password... Logon Failed \n"
;
return ;
}
printf("Welcome to program ?!!"
;
}
THERE IS NOTHING WRONG WITH CODE, JUST NEED TO KNOW HOW TO ENTER THE PASSWORD TO PASS TO MAIN ( ). Hoping to get certified..in C programming.
I have reached the stage in learning where I have come across Command Line arguments in main ( ). I can write the coding but donot know how to invoke the command line arguments for the program ?????? The truth is I wouldn't know where to start. Operating system is Windows 98, compiler is DevC++. Below is a sample program for password where the users password is passed to main in command line arguments. The program compiles and runs ok (without command entries). But how do I enter a password, e.g. Command Line argument. Every time I run the program I get message incorrect number of parameters, follow program name with parameters. HOW do I do this.
#include <stdio.h>
#include <string.h>
int main (int argc, char *argv [])
{
char password [20] = " c0mmander21 " ;
int fin;
printf(" Logon in Progress \n "
if(argc!= 2)
{
printf("Incorrect number of parameters \n"
"Follow program name with parameters \n "
return ;
}
if(!strcmp(password, argv[1]))
printf("Logon Complete..."
else
{
printf("Incorrect Password... Logon Failed \n"
return ;
}
printf("Welcome to program ?!!"
}
THERE IS NOTHING WRONG WITH CODE, JUST NEED TO KNOW HOW TO ENTER THE PASSWORD TO PASS TO MAIN ( ). Hoping to get certified..in C programming.