Should command line arguments have a null termination at the end?
The book I'm studying (Ivor Horton's Beginning C++) says they will, but my test of the code in his book shows that the null is not there.
Interestingly, in viewing the hex editor while debugging, I see that there is a "0" between each char array. For example, my command line is such:
"c:\myProgram.exe help me debug this"
then the char* array arguments, (char* argv[]) shows like this in the hex editor:
c:\myProgram.exe0help0me0debug0this0
But none of these zeros are detectable in my loop, which looks for the 0 value to end looping.
corn-fused in Indiana,
Brian
code here:
Code:
#include <iostream>
using std::cout;
using std::endl;
int main(int argc, char* argv[])
{
cout << endl;
int i = 0;
while(argv[i] != '\0')
cout << (i+1) << ": " << *argv[i] << " and string: " << argv[i++] << endl;
cout << "argc = " << argc << endl;
cout << "sizeof char* argv[]= " << (sizeof argv) << endl;
return 0;
}
Sincerely,
Brian