Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changes from Version 1 of CharArrayArgumentsExample

Show
Ignore:
Author:
jcc7 (IP: 68.97.93.38)
Timestamp:
11/12/05 04:17:54 (18 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CharArrayArgumentsExample

    v0 v1  
     1= Using char array arguments = 
     2 
     3''Part of'' ArraysCategory 
     4 
     5== Description == 
     6 
     7A basic way to use the 'args' variable in the 'main' function. 
     8 
     9== Example == 
     10 
     11{{{ 
     12#!d 
     13/* 
     14to use, type: 
     15[program name] -p [string to print] 
     16 
     17This could be more complicated, but this'll give you an idea on 
     18how to use arguments in your program. 
     19*/ 
     20 
     21int main(char[][] args) 
     22{ 
     23    // check to make sure that the number of args is correct 
     24    if(args.length < 2) // the first argument is the program name... 
     25    { 
     26        printf("No arguments given.\n"); 
     27        return 0; 
     28    } 
     29 
     30    for(int i = 0; i < args.length;i++) 
     31    { 
     32        if(args[i][0 .. 2] == "-p") 
     33        { 
     34            for(int ii = i+1; ii < args.length;ii++) 
     35            { 
     36                printf("%.*s ", args[ii]); 
     37            } 
     38            printf("\n"); 
     39        } 
     40    } 
     41    return 0; 
     42} 
     43}}} 
     44 
     45== Source == 
     46 
     47|| Link || http://www.dsource.org/tutorials/index.php?show_example=100 || 
     48|| Posted by || Anonymous (Jun 23, 2004 5:43 pm) || 
     49|| Edited by || jcc7 (Sat Oct 30, 2004 3:25 pm) || 
     50 
     51