I'm trying to convert character of a string to uppercase letters
int main (void)
{
int i = 0;
int n = 0;
static char *str[] = { "wow",
"RACEcar",
"No devil lived on.",
"rotor" };
for(i = 0; i < strlen(*str); i++)
{
if(str[i] != NULL)
{
n = function(str[i]);
}
}
return 0;
}
int function(char* x)
{
int i = 0;
int j = strlen(x);
char c;
for(i = 0; i < j; i++)
{
c = toupper(x[i]);
x[i] = c;
}
return 0;
}
I got an error saying exc bad access, code 2
at line where x[i] = c;
I'm not sure why I get this error, do I need to create another string and assign c to the new string?
toupper return the uppercase version of the character but didnt actually change the element itself, so I'm not sure what wrong with assigning the value return by toupper back to the element.