#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 :-

  1. This program/function will delete all those characters in the first string i.e s[] that matches any character in the second string i.e z[]. And copy the new string of characters to x[].

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.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

#include <stdio.h>
int main(void)
{
    int i=0,j=0,k=0,flag=0;
    char str1[100] = "Hey wassup !!!!!!" , str2[100] = "Wow cool!!!!!", newstr[100];
    while(i!='\0')                          //outer loop start
    {
        while(j!='\0')                      //inner loop start
        {
            if(str1[i]==str2[j])
            {
                flag=1;                     
                break;
            }
            j++;
        }                                   //inner loop end
        if(flag!=1)                         //value 1: char matched
        {
            newstr[k]=str1[i];
            k++;
            flag=0;

        }
         i++;  /* increament*/
    }                                       //outer loop end
    newstr[k]= '\0';
    printf(" %s",newstr);
    return 0;
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.