I'm trying to implement a function upperCase that takes a string and capitalises any characters without returning an extra string. Running the code below I get 'Segmentation fault (core dumped)' when the memcpy command runs. Am I using memcpy incorrectly?
The commented out printArrChar just loops through the array and outputs its values, which outputs the intended letters from charArray.
void upperCase(const char *s){
int i=0;
size_t len = strlen(s)+1;
char charArray[len];
while (*(s+i) != '\0'){
if (*s >=97 && *s <= 122){
charArray[i] = *(s+i) -32;
}
else
{
charArray[i] = *(s+i);
}
i++;
}
charArray[len-1] = '\0';
// printArrChar(charArray, sizeof(charArray)/sizeof(charArray[0]));
memcpy(s, &charArray, len);
}
Edit: Full code for context. https://pastebin.com/Hf7HH5yu
I realise I made a mistake declaring my function as taking a const but giving it a non-constant array, but removing the const doesn't seem to fix the error.