Command Prompt for Windows

argv, _wargv, _argtv

char *argv(int index);
wchar_t *_wargv(int index);
TCHAR *_argtv(int index);

Retrieve the command line argument index.

Parameter Description
index Specifies which argument to retrieve. Specifying an index of 0 retrieves the programs name. Command line arguments start from an index of 1.


On success it returns the address of a NULL terminated string containing the argument. On error it returns a NULL.


The argument is stored in a static buffer and is over-written each time this function is called. This function cannot be used to retrieve command line switches.

See Also

argc, argn, args, _wargs, _targs


#include "woio.h"
#include <stdlib.h>

/* Sum all value on the command line */

int main(void)
    long total;
    int i, n;

    total = 0;      /* zero total */
    if ((n = argc()) == 0) {
        perror("nothing to sum");
        return 1;

    for (i = 0;i < n;i++)
        total += atol(argv(i + 1));

	textcolor(COL_HIGHTEXT); printf("total=");
	textcolor(COL_NUMBER); printf("%ld\n", total);

    return 0;   /* error level */