Reputation: 4938
I am trying to scanf
arithmetical operands into variable. I want to put "+" into variable. I tried everything I have found but nothing has worked so far. The best thing I came with is:
char plus = "+";
char* c;
scanf("%c", &c);
if (strcmp(plus, c) == 0) {
printf("you have + in variable");
But this does not work. It seems like "+" does not get into variable plus
nor does it get scanned into variable using scanf
. Is there any trick for this?
Upvotes: 1
Views: 698
Reputation: 133609
There are multiple errors in there:
char*
(and not a char
).scanf
with %c
expects a char*
but you are providing a char**
char
with a char*
in strcmp
If you are dealing with single character operators there's no need to do things more complex than they are:
char plus = '+';
char c;
scanf("%c",&c);
if(plus == c)
printf("you have + in variable");
Upvotes: 4