0

i wanna to compare two chars , if char_1 == char_2 it must print out 1 else : print 0 but it doesn't ,

just first test is correct and the rest are false and i'll attach an example some test cases and it's output

i have this code

code

#include<stdio.h>
#include<string.h>
#include<ctype.h>


int check_char(char x , char y );
int check_spec_char(char x , char y);

int main ()
{
    int i , x;
    char k , l ;
    for(i = 0 ; i < 5 ; i++)
    {
        scanf("%c %c" , &k, &l );
        x = check_char(k , l);
        printf("%i\n\n", x);
    }
    return 0;
}


int check_spec_char(char x , char y)
{
    if(((x == 'e' || x == 'i' ) && (y == 'e' || y == 'i' )) ||
       (( x == 'p' || x == 'b') && ( y == 'p' || y =='b')))
    {
        return 1;

    } else
    {
        return 0 ;
    }
}


int check_char(char x , char y )
{
    x = tolower(x);
    y = tolower(y);

    if(x == y)
    {
        return 1 ;
    }
    else if (check_spec_char(x , y) == 1)
    {
        return 1 ;

    } else {

        return 0 ;
    }
}

test case and it's output

r  r
1
    
r  r
0
    
0
    
r  r
0
    
0
    
Process returned 0 (0x0)   execution time : 14.183 s
Press any key to continue.
Community
  • 1
  • 1
Black Kinght
  • 55
  • 1
  • 10

1 Answers1

1

Use scanf("%c %c " , &k, &l ); or scanf(" %c %c" , &k, &l ); This will consume your new line stored in buffer.

shafayat hossain
  • 1,089
  • 1
  • 8
  • 13