in C

hi all
i need some help with how to actually deal with the input data...
for example, we ask the user to input a number....
how do we judge that whether the number is an integer, float, or a long integer?
n also can we input numbers using the getchar() function? how will that be done?
thanx a lot for ur help...an early help will be highly appreciated...
thanx

Comments

  • : we ask the user to input a number....
    : how do we judge that whether the number is an integer, float, or a
    : long integer?

    Well, that comes with experience and a guess at the reasonableness of what fits. You should validate the data, it isn't likely that a person
    should have an age in employee records that is above 2 digits and we don't generally use a float. So, look for an integer and test it to see
    if it is non-negative and under 100. That takes care of most situations for say employees that will likely be less than 100 years! On the other hand, decimal fractions will occur often as measurements in a CAD program. So, know your territory and make your program defend it.

    : n also can we input numbers using the getchar() function? how will that be done?

    Not directly. getchar() takes a character from the keyboard and returns it as such. You can store the separate ASCII characters in an array or string and then verify them. Once that happens, you can use the atoi()function to return the integer value or some other appropriate version of it from the library or even write your own.

    I hope that this will help you understand what you needed to know.

  • Fist:
    This is not a C++ Builder question! Why post it on the C++ Builder message board (Note: in C++ Builder the answer is VERY easy)??? Perhaps, as a newbie you think C,C++ and C++ Builder is the same, so I'll give you the C++ solution...

    Second, the answer :-) :
    For the C++ answer, see the newbie code snippets:

    http://www.codepedia.com/1/CppNewbieCodeSnippets

    It shows how to convert a std::string to an integer and double. I am sure that you can work it out for other data types ;-)


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories