A
arnuld
it compiles without any trouble but produces "Segmentation Fault" when
i try to run it. since i am at chapter 2 so my knowledge of arrays is
limited to chapter 1:
------------------------- PROGRAMME -----------------------------
/* K&R2 section 2.8
Increment and Decrement Operators
STATEMENT: write an alternative version of squeeze(s1, s2) that
deletes each character
in s1 that matches any character in the string s2.
*/
#include <stdio.h>
void squeeze(char s1[], char s2[]);
int main(void) {
char arr1[] = "like this and this";
char arr2[] = "wxyzspqw";
squeeze(arr1, arr2);
printf("array1: %s\narray2: %s\n\nmodified_array: %s\n", arr1, arr2,
arr1);
return 0;
}
void squeeze(char s1[], char s2[])
{
int i, j, k;
for(i = j = 0; s1 != '\0'; ++i)
{
for(k = 0; s2[k] != '\0'; ++k)
{
if(s1 != s2[k])
s1[j++] = s1;
}
}
s1[j] = '\0';
}
i try to run it. since i am at chapter 2 so my knowledge of arrays is
limited to chapter 1:
------------------------- PROGRAMME -----------------------------
/* K&R2 section 2.8
Increment and Decrement Operators
STATEMENT: write an alternative version of squeeze(s1, s2) that
deletes each character
in s1 that matches any character in the string s2.
*/
#include <stdio.h>
void squeeze(char s1[], char s2[]);
int main(void) {
char arr1[] = "like this and this";
char arr2[] = "wxyzspqw";
squeeze(arr1, arr2);
printf("array1: %s\narray2: %s\n\nmodified_array: %s\n", arr1, arr2,
arr1);
return 0;
}
void squeeze(char s1[], char s2[])
{
int i, j, k;
for(i = j = 0; s1 != '\0'; ++i)
{
for(k = 0; s2[k] != '\0'; ++k)
{
if(s1 != s2[k])
s1[j++] = s1;
}
}
s1[j] = '\0';
}