I'm writing a simple code for removing spaces from a string in C however I get the following message after compiling: EXC_BAD_ACCESS (code=2, adresss=....). It's coming from the line '*temp = *str' however I don't understand why? How can I fix it?
void removeSpaces(char * str)
{
char * temp = str;
while (*str != '\0') {
if (*str != ' ') {
*temp = *str;
temp++;
}
str++;
}
*temp = '\0';
}
char * temp = strand*temp = *str.removeSpaces()? Did you pass it a string literal?