0

The problem that i'm having is that the condition always returns false and thus runs the second statement. code:

void main()
{
    char a[20],b[20],c[20],d[20];
    printf("enter your first name:");
    scanf("%s",a);
    printf("enter your second name:");
    scanf("%s",b);
    printf("enter your last name:");
    scanf("%s",c);
    (b=="none")?printf("%s %s",a,c):printf("%s %s %s",a,b,c);
}

in this (b=="none") always returns false ,i also converted this into if else statement but the results were same.

ketan ch
  • 29
  • 6
  • 2
    `b=="none"` compares the address of `b` with the address of the string literal `"none"`. Hence, it will always be false. Change it to `strcmp(b, "none") == 0`. And add `#include ` at the top. – Tom Karzes Dec 22 '22 at 14:23

0 Answers0