Using char array arguments
Part of ArraysCategory
Description
A basic way to use the 'args' variable in the 'main' function.
Example
/* to use, type: [program name] -p [string to print] This could be more complicated, but this'll give you an idea on how to use arguments in your program. */ int main(char[][] args) { // check to make sure that the number of args is correct if(args.length < 2) // the first argument is the program name... { printf("No arguments given.\n"); return 0; } for(int i = 0; i < args.length;i++) { if(args[i][0 .. 2] == "-p") { for(int ii = i+1; ii < args.length;ii++) { printf("%.*s ", args[ii]); } printf("\n"); } } return 0; }
Source
Link | http://www.dsource.org/tutorials/index.php?show_example=100 |
Posted by | Anonymous (Jun 23, 2004 5:43 pm) |
Edited by | jcc7 (Sat Oct 30, 2004 3:25 pm) |