#include<stdio.h>
void squeez(char s[],char z[]);
int main()
{
char s[100] = "Hey wassup !!!!!!";
char z[100] = "Wow cool!!!!!";
squeez(s,z);
return(0);
}
void squeez(char s[] , char z[])
{
int j,dummy = 0,i=0;
char x[100];
for(j = 0 ; s[j] != '\0';j++)/* the starting loop */
{
while(z[i] != '\0') /* inner loop */
{
/ if(s[j] ==z[i])
{
dummy = 123;
break;
}
i++;
}
if(dummy != 123)
{
x[j] = s[j];
dummy = 0;
}
}
printf("%s",x); /* printing out the values */
}
The main aim of making this program is that :-
- This program/function will delete all those characters in the first string i.e
s[]
that matches any character in the second string i.ez[]
. And copy the new string of characters tox[]
.
Problems :-
The program is not giving the right output it is printing some garbage value.
Questions:-
Help me with this piece of code . Tell me where i am wrong and what is the solution.
Thank you IN advance.