menu prev

COMMAND LINE ARGUMENTS
When a program is invoked, it may accept arguments from the command line such as the name of a data file to process.

In TurboC, the two functions ParamCount and ParamStr are used to retrieve these values.

ParamCount
This function returns the number of arguments of the command line which follow the name of the program. In this example below,



        test  file1.c  file2.pas

the program test is invoked with two parameters.

ParamStr
This function returns a string representing the value of the command-line parameter.




program commandline( output );



var arguments : integer;



begin

    if ParamCount = 0 then

    begin

         writeln( 'No parameters supplied' );

         halt(1)

    end

    else begin

         writeln('There are ', ParamCount, ' parameters' );

         for arguments := 1 to ParamCount do

             Writeln( 'Parameter ',arguments,' = ',ParamStr(arguments) );

    end

end.




Copyright B Brown/P Henry/CIT, 1988-1997. All rights reserved.
menu prev