90 ASCII representation?

This is a discussion on 90 ASCII representation? within the C Programming forums, part of the General Programming Boards category; I've looked at the ASCII table below: http://www.lookuptables.com/ it doesn't seem to mention anything about a 90 representation of a ...

  1. #1
    Learner Axel's Avatar
    Join Date
    Aug 2005
    Posts
    335

    90 ASCII representation?

    I've looked at the ASCII table below:

    http://www.lookuptables.com/

    it doesn't seem to mention anything about a 90 representation of a char

    so i tried the following:

    Code:
      char zero  = 48;
      char ninty = 57+48; // prints out i. 
      char ninty2 = (char) 67; // prints out C ? :|
    but i can't seem to get an ASCII representation of 90 as a char.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Code:
    char num[] = "90";
    printf("%s\n", num);

  3. #3
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Do you realize that "90" is 2 chars ?
    Guess you want sth like this

    Code:
    char ninety[3];
    ninety[0]=57;
    ninety[1]=48;
    ninety[2]=0;
    printf("%s", ninety );
    Kurt

  4. #4
    Learner Axel's Avatar
    Join Date
    Aug 2005
    Posts
    335
    is there anyway of storing as a char and not in an array?
    what i want to do is check if a number entered is between 0 and 90.

    Code:
      char num[] = "90";
      char num2[] = "0";
      char numinput;
    
    scanf("%c", &numinput);
    
      while (numinput !=  num < num2)
      {
        printf("%s", "You entered a number greater than 90, please try again:");
        scanf("%c", &numinput);
    
      }

  5. #5
    Nonconformist Narf's Avatar
    Join Date
    Aug 2005
    Posts
    174
    what i want to do is check if a number entered is between 0 and 90.
    So use a number:
    Code:
    int num;
    
    if (scanf("%d", &num) == 1 && num >= 0 && num <= 90)
      printf("%d is valid\n", num);
    Just because I don't care doesn't mean I don't understand.

  6. #6
    Learner Axel's Avatar
    Join Date
    Aug 2005
    Posts
    335
    is there anyway to check if it's not valid i.e i tried the following:

    if (scanf("%d", &num) == 1 && !num >= 0 && !num <= 90)
    printf("%d is not valid\n", num);

    but every everything i enter it just says it's not valid

  7. #7
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    If you want to reverse the logic you havee to use ||
    Code:
    if (scanf("%d", &num) != 1 ||  num < 0 || num > 90)
       printf("%d is not valid\n", num);
    Kurt

  8. #8
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    ! has higher precedence than >=, so !num will become either 0 or 1. since both 0 and 1 are always <= 90 and always >= 0, your if is always true. Try:
    Code:
    if (scanf("%d", &num) != 1 || num < 0 || num > 90)
        printf("%d is not valid\n", num);

  9. #9
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Read this for advice on getting a number from the user:
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385

    You cannot use scanf() to reliably determine if the user entered a valid number or not.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  2. Office access in C/C++ NOT VC++!! :)
    By skawky in forum C++ Programming
    Replies: 1
    Last Post: 05-26-2005, 02:43 PM
  3. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 11:36 AM
  4. ascii values for keys
    By acid45 in forum C Programming
    Replies: 2
    Last Post: 05-12-2003, 08:13 AM
  5. Checking ascii values of char input
    By yank in forum C Programming
    Replies: 2
    Last Post: 04-29-2003, 08:49 AM

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