So, I am trying to learn map
in C++. I put the type as std:: map <const char *, int>
to a variable month
.
Say, the data is month["Jul"] = 7;
When I tried to retrieve the value directly
printf("%d", month["Jul"]);
It succeeds and outputs the value.
7
Trying with another variable succeeds too.
const char *p = "Jul";
printf("%d", month[p]); // 7
But strange behavior happens when I tried to assign it with a given input.
const char in_month[3];
scanf("%s", in_month);
print("%d". month[in_month]);
It retrieves (null)
0
Did I do something forbidden here or was there a step that I missed?