This is a question regarding a pointer to a string versus pointers (plural) to an array of strings. Here is the code - please see comments for the problem:
int main(int argc, char** argv) {
// Here, we're just loading each string into an incrementing pointer and printing as we go. It's not an array of pointers. This works fine.
char* dumb = NULL;
cout << argc << endl;
for (int i = 0; i < argc; i++) {
dumb = argv[i];
cout << dumb << endl;
dumb++;
}
// Next we'll try to load the strings into an array of pointers, and print them out. This causes an error (see below).
char** dumber = NULL;
cout << argc << endl;
for (int i = 0; i < argc; i++) {
*(dumber + i) = argv[i];
cout << dumber[i] << endl;
}
return 0
}
Unhandled exception at 0x001899F7 in Testing.exe: 0xC0000005 : Access violation writing location 0x00000000.
Could someone please correct me?
dumber. I wonder what kind of result you expect.dumb++;does nothing -- you are already incrementingiforargv[i], so placingdumb++;at the end has no effect on your code (it actually just increments the lastargv[i]pointer by 1, but then you reassign the pointer anyway)