argv is a char**
, a pointer to a pointer. Think of it as an array of strings, not a string.
Indexing with [i]
removes one level of indirection, so argv[i]
is a pointer to a character, a char*
.
toupper()
is int toupper (int c);
- it expects a single character as an integer, not a pointer to a character, but you are passing it a char*
when you do argv[i]
, which you are then trying to cast to a char
... a regular old character, which typically has a different size to a pointer.
argc
says how many command line arguments there are, and argv[0]
is usually the exectuable name. Use strlen
to get the length of each argument in argv
.
To convert the whole of each argument to upper case:
for (int i = 0; i < argc; i++) {
size_t len = strlen(argv[i]);
for (size_t j = 0; j < len; j++) {
argv[i][j] = (char)toupper((unsigned char)argv[i][j]);
}
}
You can read about why the argument to toupper()
should be cast to unsigned char
in Keith Thompson's excellent answer elsewhere on SO