How to read "string" from command line argument in C? -
i've question passing in parameters via command line.
my main()
looks like
int main(int argc, char **argv){ int b, d, n, flag; char *init_d, tst_dir[100]; argv++; init_d=*(argv++); //printf(); <--------what have init_d can print later?
if argv
pointer array of pointers i'm assigning init_d
point value being pointed pointer argv
points to? (if makes sense)
i assume have value character array in order print out if don't know size of "string" passing in, not sure how achieve this. instance if run code './myprogram hello' compared './myprogram alongerinput'
you can print arguments without transferring them character arrays. null-terminated c strings , printf
eats them breakfast:
for (i=0; i<argc; i++) printf("%s\n", argv[i]);
Comments
Post a Comment