I'm trying the squeeze
program from K&R. However, I keep getting a bus error. The code below directly triggers the problem. Shouldn't this be portable?
int main() {
char* str = "foo";
for (int i = 0, j = 0; str[i]; ++i)
str[j] = '.';
}
The function from the book:
void squeeze(char s[], int c)
{
int i, j;
for (i = j = 0; s[i] != '\0'; i++)
if (s[i] != c)
s[j++] = s[i];
s[j] = '\0';
}