R
remlostime
ex 2-4 write squeeze(s1, s2), which make s1 doesn't contain any char
int s2
now I write the code:
it seems that something wrong in
if (s2[k] == '\0')
s1[i++] = s1[j];
because i write some test code in it, it shows that
but I dont know why, can anyone tell me?
#include <iostream>
using namespace std;
void squeeze(char s1[], char s2[])
{
int i = 0;
for(int j = 0; s1[j] != '\0'; j++)
{
int k;
for(k = 0; s2[k] != '\0' && s1[j] != s2[k]; k++);
if (s2[k] == '\0')
s1[i++] = s1[j];
}
s1 = '\0';
}
int main()
{
char *a = "abcedaba";
char *b = "ab";
squeeze(a, b);
printf("%s\n", a);
}
int s2
now I write the code:
it seems that something wrong in
if (s2[k] == '\0')
s1[i++] = s1[j];
because i write some test code in it, it shows that
but I dont know why, can anyone tell me?
#include <iostream>
using namespace std;
void squeeze(char s1[], char s2[])
{
int i = 0;
for(int j = 0; s1[j] != '\0'; j++)
{
int k;
for(k = 0; s2[k] != '\0' && s1[j] != s2[k]; k++);
if (s2[k] == '\0')
s1[i++] = s1[j];
}
s1 = '\0';
}
int main()
{
char *a = "abcedaba";
char *b = "ab";
squeeze(a, b);
printf("%s\n", a);
}