As far as I understand, and I'm probably wrong, in int main(argc, *argv[]) argv is a pointer to a pointer of an array of strings. I want to do something like
But I get the error that I can not convert from int to char*. How would I access the actual value in argv? I thought about *argv but wouldn't that just return the memory address of the thing pointed to by the pointer argv is pointing to? Also, I am not sure to use '1' or "1", because it seems like it points to an array of strings but it is declared as a pointer to char? Any help is appreciated.
The second parameter of main is actually an array of C strings. C strings are an array of characters themselves so in the long view, so the second parameter is actually a two dimensional array. To access a specific character one may do the following:
argv[i][x]; //i is the number parameter, where x is the number of character in the sequence.
You could also use some functions in the standard string library:
What about if I want to locate "/?" within a cstring? Is it possible to search for an explicit string in a cstring? I saw strpbrk does that, but it looks for '/' and '?', I just want "/?"
argv is an array of pointers to char arrays (strings). argv[i] is a char array (string). argv[i][j] is a char (a character)
With argv[i] == '1', You are comparing a char array (string) with a char.
The poor old compiler can't do what it instinctively wants to do, which is convert '1' to an int, then to a char array (string), but it can't; so it's telling you it can't.
You can search for a string in another string with strstr. It either returns the string it found or NULL.
Array indexes start at 0, in C++. I see that the for loop in the original post is starting at index 2, that should probably be a 1 (0 would be the name of the executable).