cant we compare two for inequality?

i mean if i have a char array 'a' and i want to know the number of digits in an array which is not '4' or not '7'

i.e if my array has value 4567778 the output should be 3 as there are three 7's and one 4 so output is 3.
my condition for check is (a!=52!!a!=55).
but this condition is never checked and if my condition is (a==52!!a==55) i got right output.

so that means we can only compare if the strings are equal?
this code give wrong output:


#include<stdio.h>

int main()

{
    int t,i,o;
    char a[100000];
    

scanf("%d",&t);
    while(t--)
    {
        i=0;
        o=0;
    scanf("%s",a);
    
    
    while(a[i]!=NULL)
    {
        
        if(a[i]!=52||a[i]!=55)      //this condition is not working?
         o++;
        i++;
    }

printf("%d",o);
}    

    return 0;
}

this works fine:

#include<stdio.h>
//#include<string.h>
//#include<conio.h>

using namespace std;

int main()

{
    int t,i,o;
    char a[100000];
    
//    cin>>t;
scanf("%d",&t);
    while(t--)
    {
        i=0;
        o=0;
    scanf("%s",a);
    
    
    while(a[i]!=NULL)
    {
        
        if(a[i]==52||a[i]==55)
         o++;
        i++;
    }

printf("%d ",i-o);
}    

    return 0;
}

oopes the first line is :Cant we compare two strings for inequality?

char a[100000];

maybe you meant to use an array of integers since your just using numbers?

if(a!=52||a!=55) //this condition is not working?

Since you want to count those which are not 4 or which are not 7,
this should work according to me...

if(a[i]!=52 && a[i]!=55)

Use AND condition

@djsan...yeah you are right,my mistake..:)

Mark it solved if it is working

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.