// video from ECE 1620, April 2020: FC-2020-04-w15.1:argc,argv.mp4 // https://drive.google.com/file/d/10CnNJS0u3AFUtrzA6yymMfVS5KQ_fsrl/view // #include #include // for int atoi(), long atol(), long long atoll(), double atof() #include // // int main( void) // no access to command-line arguments // // int main( int count, char *words[]) // words[i] is a string from the command-line // int main( int argc, char *argv[]) // using traditional names for the arguments { // for( int i = 0; i < count; ++i) printf( "%i: %s\n", i, words[i]); for( int i = 0; i < argc; ++i) printf( "%i: %s\n", i, argv[i]); int n=0; if( argc > 1) n = atoi(argv[1]); // convert string to int double d=0; if( argc > 2) d = atof(argv[2]); // convert string to double printf( "n = %i, d = %g\n", n, d); return 0; } /* sample runs: $ gcc -Wall args.c $ ./a.out abc efg < args.c | cat 0: ./a.out 1: abc 2: efg n = 0, d = 0 $ ./a.out 1234 56.78 0: ./a.out 1: 1234 2: 56.78 n = 1234, d = 56.78 $ */