Determining a variable type...

This is a discussion on Determining a variable type... within the C Programming forums, part of the General Programming Boards category; Hi, i was wondering if there was a way to determine the variable type of a number taken from a ...

  1. #1
    Registered User -leech-'s Avatar
    Join Date
    Nov 2001
    Posts
    54

    Question Determining a variable type...

    Hi, i was wondering if there was a way to determine the variable type of a number taken from a user input. For example:
    Code:
    if(input == float)
    {
         Do something;
    }
    else if(input == short || int || long)
    {
         Do something else;
    }
    This is just for general knowledge so i don't have any real exmaple to give, but that's the basic idea.

    Thanks.
    Not yet, have to think of one...

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Hi, i was wondering if there was a way to determine the variable type of a number taken from a user input. For example:
    Yes and no. No, not in the way you're trying. Yes, you could if you read into a buffer first and then stick it in the smallest compatible data type.

    You could also use sscanf() to stick it into various variables and see how that works.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    no idea
    Guest
    what are you checking? for a varible to exist you must have declared it so you should know its type, the only way you could check 'incode' would be to check it's size, however some ints are the same size. If your talking about parsing a string then you will have to check each character individually to determine what you have.
    Does that help? No I thought not.

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    You could read it as a string, then check what kind of input it could be.

    ie:
    Just digits (0-9): Integer
    Digits and one . (dot): Float
    One digit/character: Char
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  2. strings Vs. Char pointers
    By aijazbaig1 in forum C Programming
    Replies: 49
    Last Post: 02-13-2008, 08:51 AM
  3. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 02:49 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21