1

When I type hk on the Output, it did not say HONG KONG, It just say INPUT ERROR everytime.

char dc,ds[15];
int main(int argc, char *argv[]) {
p("Destination Code: ");
s("%s", &dc);

if(dc=="hk"){
    strcpy(ds, "HONG KONG");
}
else{
    strcpy(ds, "INPUT ERROR");
}

p("Destination: %s", ds);
return 0;
Filburt
  • 17,626
  • 12
  • 64
  • 115
Kokie
  • 21
  • 3

1 Answers1

2

Two problems here.

  1. You have declared dc as char type and trying to read in the string type.

  2. You cannot use == to compare two strings, you should use strcmp instead.

Example:

  char dc[3];    
  scanf("%2s", dc);
  if(strcmp(dc,"hk") == 0){
    strcpy(ds, "HONG KONG");
  }
  else{
     strcpy(ds, "INPUT ERROR");
  }
kiran Biradar
  • 12,700
  • 3
  • 19
  • 44