I have a simple function that should convert lowercase characters to uppercase. But at a certain point, I get a bus error. What does this error mean and how can it be fixed?
PS I've been trying to figure out what this error means for a long time and as a result I can't figure out what the difference is between bus error and segmentation fault
void *to_upper(const char *str) {
char *strCopy = (char *)str;
int strLength = strlen(strCopy);
for (int i = 0; i < strLength; i++) {
if (strCopy[i] >= 'a' && strCopy[i] <= 'z') {
strCopy[i] = (int)strCopy[i] - 32; // ERROR -> zsh: bus error ./a.out
}
}
return strCopy;
}
printf("to_upper: %s", (char *)to_upper("TeSt"));