0

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.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by urbangeek
2

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

0

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:

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.