problem was first posted here. lionaneesh got a problem with this question. I tried to solve that question myself. He solved himself, but i failed.
the questions is:

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

here is my code:

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

The problem is newstr is not getting printed...infact line 20 is not working i think....

Thanks in advance.

didnt see you logic but i guess here is the problem

while(i!='\0')
while(j!='\0')

it should have been str and atr[j] insteed

didnt see you logic but i guess here is the problem

while(i!='\0')
while(j!='\0')

it should have been str and atr[j] insteed

oh...you're right...:twisted:

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.