Click here to Skip to main content
14,830,889 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
str[j] != '\0'
what it means?
and how to remove duplicate character by comparing both string and print final result.
if str1=A,B,C,D
and str2=A,C,E,F,B
Posted
Comments
xenotron 7-Sep-12 6:03am
   
Instead of str[j]!='\0' you can write str[j]!=0 or simply str[j] because of the automatic conversion between c types.

1 solution

The following line of code checks to see if the current character is the null terminator. A null terminator indicated the End Of String.
C++
str[j] != '\0'

This is usually used in a while loop to check if the last charecter of the string has been reached. If it is the last char, the loop will terminate.

Check this resource: http://www.cprogramming.com/tutorial/c/lesson9.html

I assume you want to remove characters common to both strings. You could do this:
C++
int i=0, j=0, index=0;
char tmp;

while(str1[i] != '\0')
{
tmp = str[i];
    while(str2[j] != '\0')
    { 
         if(  tmp != str2[j] ) 
             { 
                  
                result[pointer] = tmp;     // Copy the non common charecter to result array
                pointer++;                 // Increment pointer

             }   
     j++;
    }
i++;
}
   
v2
Comments
Surendra0x2 7-Sep-12 5:24am
   
Thanks sir i got it :)
Shaunak De 7-Sep-12 5:28am
   
Your welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900