#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 */
		{
/* the purpose of dummy is to tell weather this if statement became true or not */
			if(s[j] = z[i])
			{

				dummy = 123;	
		
				break;
			}	
			else
			{
				continue;
			}
			i++;
		}
		if(dummy != 123)
			{
				x[j] = s[j];
			}
	}
	
	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.

jephthah commented: code tags. formatted. worked out solution w/o being given code. time to make you green. +6

Recommended Answers

All 8 Replies

if(s[j] = z)

Test for equality, in this line of code, don't assign a value.

Then go ahead with your logic.

I believe you can delete the Dummy variable, entirely. ;)

if(s[j] = z)

Test for equality, in this line of code, don't assign a value.

Then go ahead with your logic.

I believe you can delete the Dummy variable, entirely. ;)

sir dint understand ur answer..

One = is for assignment. You need two =='s for a test of equality.

All if(something == somethingElse) lines of code, need two =='s.

One = is for assignment. You need two =='s for a test of equality.

All if(something == somethingElse) lines of code, need two =='s.

#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 */
		{
/* the purpose of dummy is to tell weather this if statement became true or not */
			if(s[j] == z[i])
			{

				dummy = 123;	
		
				break;
			}	
			else
			{
				continue;
			}
			i++;
		}
		if(dummy != 123)
			{
				x[j] = s[j];
			}
	}
	
	printf("%s",x); /* printing out the values */
}

the above code also dosent works ..

now the problem is that there is no output on the screen..

and the program is asking input just like getchar();

Done the solutin thanks all

well...i done this...why it's not working??:?:

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

        }
    }                                       //outer loop end
    newstr[k]= '\0';
    printf(" %s",newstr);
    return 0;
}
commented: the point, here, is to provide advice and/or code snippets that leads the poster to work out a solution. the point is NOT to add your own problems on top of things. -1

@urbangeek :

1) don't post full code solutions to poster's questions.

2) DEFINITELY dont post broken code to a poster's question

3) if you've got problems, take them to a new thread of your own creatioon. Don't confuse a poster by cluttering up their question with your problems.

in short, if you don't know what you're doing, stop helping. ask and learn all you want in your own threads.

@urbangeek :

1) don't post full code solutions to poster's questions.

2) DEFINITELY dont post broken code to a poster's question

3) if you've got problems, take them to a new thread of your own creatioon. Don't confuse a poster by cluttering up their question with your problems.

in short, if you don't know what you're doing, stop helping. ask and learn all you want in your own threads.

Sorry, i was not helping...this thread was solved...i tried this problem myself but cant make it work...so i asked where i did wrong....
my bad....i'm creating a new thread...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.