subscripted value is neither array nor pointer nor vector with argv
I have this code.c in ubuntu in terminal but when I compile it with gcc this error appeared
cod2.c: In function ‘main’:
cod2.c:9:11: error: subscripted value is neither array nor pointer nor vector
why is that?
int main(int argc , char ** argv){
mkdir(argc[1] , 00755);
return 0;
}
You got confused between argc (an int representing the number of arguments) and argv (an array of strings containing the command line arguments). Change:
mkdir(argc[1], 00755);
to:
mkdir(argv[1], 0755);
^^^^^^^
(Note that I also removed a redundant 0 prefix from 00755 to make it 0755 - you only need a single 0 prefix to signify octal base.)
For a real program you should also check that an argument has been provided, otherwise you will crash when the user does not supply an argument:
if (argc > 1)
{
mkdir(argv[1], 0755);
}
mkdir(argv[1] , 00755);//try argv instead of argc
Your command line arguments are stored in argv only, not in argc . argc contains no of arguments in command lines. So try with argv
上一篇: 为什么既不移动语义也不会按预期工作?
