I need to get an integer number with only using getchar() and without pre knowing the number of digits in the integer.
And I cannot use strings or arrays.
Any ideas?
Thank you
I need to get an integer number with only using getchar() and without pre knowing the number of digits in the integer.
And I cannot use strings or arrays.
Any ideas?
Thank you
Read in a character. if it's a digit, process it; if it's not, you're done.
Presumably you know how, if you already have 6, and then you see a 4, how to (numerically, not in terms of strings) turn that into 64, and then turn that into 644 when another 4 comes in, etc. (If not, look up "place value".)
Thank you tabstop
I don't know how I have looked for "place value", yield nothing.
could you please direct me to a link or somethin.
I'm going to enter the number 1024 - break down the problem...
1 Value entered so far is 1
0 Value entered so far is 10
2 Value entered so far is 102
4 Value entered so far is 1024
Have a look at the number entered so far - There is a algorithm for adding a new digit. Ask yourself what is happening to the number each time a new digit is entered.
Every time a new character is entered, you need to valadate it (make sure it is a number), and then enter it into your algorithm for adding a new digit.
Fact - Beethoven wrote his first symphony in C