O
Owner
Can this code determine number of aruments?
sizeof argv / sizeof argv[0]
I'd appreciate any comments
sizeof argv / sizeof argv[0]
I'd appreciate any comments
Can this code determine number of aruments?
sizeof argv / sizeof argv[0]
I'd appreciate any comments
Can this code determine number of aruments?
sizeof argv / sizeof argv[0]
Can this code determine number of aruments?
sizeof argv / sizeof argv[0]
I'd appreciate any comments
Assuming that you use argv in the sense of the 2nd argument to main()
i.e.
char **argv;
or
char *argv[];
then, NO]
sizeof argv / sizeof argv[0]
does not give you the number of arguments in the argv[] array.
It /does/ give you
the number of char * pointers that can fit in a char ** pointer;
a singularly useless tidbit of information.
Can this code determine number of aruments?
sizeof argv / sizeof argv[0]
I'd appreciate any comments
Owner said:Can this code determine number of aruments?
sizeof argv / sizeof argv[0]
I'd appreciate any comments
I need to build a copy of argv in main, so before that
need to determine how many arguments are there, so I can do
this
char *newargv["number of arguments"];
char *newargv[argc] didn't work. it says it has to be
constant expression
sizeof argv did give me size of a pointer which is 4
Ian Collins said:Assuming that you use argv in the sense of the 2nd argument to
main() i.e.
char **argv;
or
char *argv[];
then, NO]
sizeof argv / sizeof argv[0]
does not give you the number of arguments in the argv[] array.
It /does/ give you
the number of char * pointers that can fit in a char **
pointer;
a singularly useless tidbit of information.
No, it gives you the size of a char**.
Dr Nick said:So you either need to use a compiler that char *newargv[argc] works on,
or do something with malloc and free, or use a not-quite-standard thing
like alloca to get yourself some space.
Can this code determine number of aruments?
sizeof argv / sizeof argv[0]
I'd appreciate any comments
I need to build a copy of argv in main, so before that
need to determine how many arguments are there, so I can do
this
char *newargv["number of arguments"];
char *newargv[argc] didn't work.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.