Originally Posted by
TyrioN
Hello
im trying to write a program that is required to use the getchar method.
the variables (there is two) is of type int and float.
is the coding for it
int a = (getchar() != '\n');
will this read a number greater than one digit, like 15. if not who do i write it so it does read bigger numbers.
::edit
The following does not solve your problem - see Hammer's post below - I added a couple of comments on your use of getchar() for information purposes..
You did ok to assign the value from getchar() to an int, but you should note that you need some extra brackets
Code:
/* != is of higher precendence than = , so what you really have
is this: */
a = (getchar() != '\n')
What the above code does is to test the return value of getchar() against '\n' and then sets the variable a to 1 or 0. Not exactly what you want.
Try some extra brackets:
Code:
int a = 0;
(a = getchar()) != '\n'
~/