// GatewayId = "T5YCD1"; \\ Uncomment and it fails?
printf("Gateway Id = --%s--\n", GatewayId);
printf("GATEWAY_ID = --%s--\n", GATEWAY_ID);
if (GatewayId == GATEWAY_ID) {
printf("They match 1\n");
}
else {
printf("They do not match 1\n");
int a = 0;
while ((unsigned)a <= strlen(GatewayId))
{
char byte1 = GatewayId[a];
char byte2 = GATEWAY_ID[a];
printf(" bytes is %d %d\n", byte1, byte2);
a++;
}
}
GATEWAY_ID = GatewayId;
printf("Gateway Id = --%s--\n", GatewayId);
printf("GATEWAY_ID = --%s--\n", GATEWAY_ID);
if (GatewayId == GATEWAY_ID) {
printf("They match 2\n");
}
else {
printf("They do not match 2\n");
}
}
This is an excerpt from a larger program an the calling functions require const char*.
When you run the app with an input argument of T5YCD1
They will display the same, the byte by byte will be the same.
The second if statement says they match.
I tried changing the if statement to
if(*GatewayId == *GATEWAY_ID)
and it report they match, even when they don't. I changed
GATEWAY_ID = "T5YCD1"; to
GATEWAY_ID = "T5YCD2";
just to test.
An kept the same input of T5YCD1.
I am new to c++.
Do i need to do the assignment of string to const char* a different way.
I tried changing the if statement to if(*GatewayId == *GATEWAY_ID)
Dereferencing a pointer-to-char, gives you a char. You can't compare a string to another by comparing a single character of one to a single character of the other. Perhaps you should avail yourself of the suggestion to use std::strcmp.