I pass a character to my program and I want to store this character to variable. For example I run my program like this ./a.out s file
. Now I want to save the argv[1] (its the s) to a variable (lets say I define it like this char ch;
. I saw this approach:
ch = argv[1][0];
and it works. But I cant understand it. The array argv isnt a one dimensional array? if i remove the [0], I get a warning warning: assignment makes integer from pointer without a cast
char *argv[]
-- it's a pointer-to-pointer. (You can think of it as a pointer to the first element of an array of pointers-to-char
). – Jacquelynnjacquenettaargv is a one-dimensional array of strings
. thats why I thought it was a one dimensional. – Hashum