0

I want to make a calculater that takes input like 23 + 24 The two ints or floats plus the character in the same line Tried float a = Getfloat(); char c = GetChar(); float b = Getfloat();

With this code i am forced to press enter after every variable. Is there a way to get the inputs of these variables in a single line 23+24?

1 Answer 1

2

Yes there is. You can use scanf() from stdio.h.

As an example imagine you want to input 2 + 2.

An option can be the this:

int a, b;
char c;

scanf("%d", &a);
scanf(" %c", &c);
scanf("%d", &b);

Notice the space before the char placeholder, this is to ignore the spaces, don't needed if the input is 2+2, or the same in one line:

scanf("%d %c%d", &a, &c, &b);

Again the space between the first int and the char is to ignore the spaces.

More on scanf()

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .