linux - input directory as command line arguement in c -
i building program copies directories each other, can work hard coded.
i want directory input user via command line argument.
i have used
char srcpath[] = argv[1];
however when hard code
char srcpath[] = "home/user/desktop/cat"; works fine.
but doesn't work, can explain why / suggest way this? , there special way directories have input when used in cli?
argv[]
array of char pointers, therefore when use argv[1]
obtaining second item in array char pointer. james suggested if want store value of argv[1]
memory address have use identical type in case char *
.
if need save directory path sort of processing or manipulation, need store command line argument inside char array.
char srcpath[100]; int i; (i = 0; argv[1][i] != '\0'; i++) { srcpath[i] = argv[1][i]; }
array names pointers using subscript []
dereferences it. same can said char arrays stored inside of argv[]