squeeze(s1, s2),将字符串s1中任何以字符串s2中字符匹配的字符都删掉
#include <stdio.h>
void squeeze(char s1[], char s2[])
{
int i, j, k;
for (i = k = 0; s1[i] != '\0'; i++){
for (j = 0; s2[j] != '\0' && s2[j] != s1[j]; j++)
;
if (s2[j] == '\0')
s1[k++] = s1[i];
}
s1[k] = '\0';
}
main()
{
char s1[], s2[];
s1 = "1234567";
s2 = "345";
squeeze(s1, s2);
printf ("%s, %s" s1, s2);
}
出错显示
squeeze_12.c: In function ‘main’:
squeeze_12.c:18:7: error: array size missing in ‘s1’
squeeze_12.c:18:13: error: array size missing in ‘s2’
squeeze_12.c:19:5: error: incompatible types when assigning to type ‘char[1]’ from type ‘char *’
squeeze_12.c:20:5: error: incompatible types when assigning to type ‘char[1]’ from type ‘char *’
squeeze_12.c:22:19: error: expected ‘)’ before ‘s1’
squeeze_12.c:22:19: warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat]
squeeze_12.c:22:19: warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat]
https://github.com/thvdburgt/KnR-The-C-Programming-Language-Solutions/blob/master/Chapter%202/2-4/squeeze.c