/* squeeze: delete all c from s */
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';
}
int main(void)
{
squeeze("squeeze", 'z');
return 0;
}
我用 gcc 编译并运行它,结果出现了分段错误。这个例子有什么问题吗?
感谢男人,我刚刚犯了一个常见的错误。