J
jacklisp
I have wrote a small function but got the error
function:
/*< squeeze */
void squeeze(char s1[],char s2[])
{
int de_s ;
int i,j,k;
for(i = 0;s2 !='\0';++i)
{
de_s = s2;
for(j = k = 0;s1[j] != '\0';++j)
{
if(s1[j] != de_s)
{
s1[k++] = s1[j];
}
}
s1[j] = '\0';
}
//printf("s1:%c",s1[0]);
}
/*>*///end-squeeze
the function just deletes each character in s1 that matches any
character in the string s2.(exercise from the c language
programming).But it doesn't work and I got
the message form GDB:
Starting program: /home/jack/myPro/myC/ListTest/CprogrammingTest/
Char01/main
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400659 in squeeze (s1=0x40098b "abcdefb", s2=0x400988
"ab") at main.c:40
I use squeeze("abcdefb","ab") to call the function.
Any suggestion?
Thanks
function:
/*< squeeze */
void squeeze(char s1[],char s2[])
{
int de_s ;
int i,j,k;
for(i = 0;s2 !='\0';++i)
{
de_s = s2;
for(j = k = 0;s1[j] != '\0';++j)
{
if(s1[j] != de_s)
{
s1[k++] = s1[j];
}
}
s1[j] = '\0';
}
//printf("s1:%c",s1[0]);
}
/*>*///end-squeeze
the function just deletes each character in s1 that matches any
character in the string s2.(exercise from the c language
programming).But it doesn't work and I got
the message form GDB:
Starting program: /home/jack/myPro/myC/ListTest/CprogrammingTest/
Char01/main
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400659 in squeeze (s1=0x40098b "abcdefb", s2=0x400988
"ab") at main.c:40
I use squeeze("abcdefb","ab") to call the function.
Any suggestion?
Thanks