Download presentation
Presentation is loading. Please wait.
Published byGordon Golden Modified over 8 years ago
1
Command line arguments
2
– main can take two arguments conventionally called argc and argv. – Information regarding command line arguments are passed to the program through argc and argv.
3
Command line arguments can give input to C program from command line E.g. > prog.c 10 name1 name2 …. how to use these arguments? main ( int argc, char *argv[] ) argc – gives a count of number of arguments (including program name) char *argv[] defines an array of pointers to character (or array of strings) argv[0] – program name argv[1] to argv[argc -1] give the other arguments as strings
4
Command line arguments #include main(int argc,char *argv[]) { int i; for(i=0;i<argc;i++) { printf(“%s”,argv[i]); }
5
Arrays Memory Layout
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.