arrays - C-programming board game -


this question has answer here:

i trying make board game maximum board width 80 cells , maximum board height 52 cells, user should able choose dimensions entering them command line, dimensions smaller maximum. new programming know command line arguments passed through main function in c, i've been stuck on , cant seem find answers.

can thank you.

the main function takes 2 arguments, integer called argc , array of string pointers called argv. main declared as:

int main(int argc, char *argv[]) 

the argc variable number of arguments passed program.

the argv variable contains actual arguments pass program.

the argc variable at least equal 1, actual program name passed argument, , in argv[0].

if want 2 arguments, first have make sure argc @ least equal 3. first argument program stored string in argv[1], , second in argv[2].


i recommend experiment program such this:

#include <stdio.h>  int main(int argc, char *argv[]) {     printf("argc = %d\n", argc);      (int = 0; < argc; i++)         printf("argv[%d] = \"%s\"\n", i, argv[i]);      return 0; } 

and (and unrelated problem interesting none less) fact size of argv array 1 larger people expect. size of argv array argc + 1 , can indexed argv[0] (the program name) argv[argc]. last entry (argv[argc]) null pointer.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -