// Argc and Argv demo

#include <stdio.h>

int main(int argc, char *argv[]) {
    // in this program, there's an array of strings called argv
    // we know that argv is exactly argc long
    // we don't know the length of each string, they're all possibly different
    
    printf("The name of this program is: %s.\n", argv[0]);
    
    printf("Here are the rest of the words in the command line.\n");
    
    int i = 1;
    while (i < argc) {
        fputs(argv[i], stdout); // printf("%s", argv[i]);
        putchar('\n'); // printf("\n");
        i++;
    } 
}

Resource created Tuesday 11 August 2020, 07:40:14 PM.

file: args.c


Back to top

COMP1511 20T2 (Programming Fundamentals) is powered by WebCMS3
CRICOS Provider No. 00098G