Thread: 3 Questions

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    75

    Exclamation 3 Questions

    My first two questions refer to the code below and are:
    1)What do I have to write '1' and '5' with commas('')?? If I dont put them the loop never ends.
    2) Why return i-'0 instead of just return i??? Is it because the getche adds a '\0' character at the end of the entered character or something??

    do{
    printf("Introduzca su eleccion: ");
    i=getche();
    printf("\n");
    }while(i<'1' || i>'5'); //sin comillas?
    return i-'0';

    Last question: why in this 'if' I have to put the * and if I dont do it wont work? Phone[loc] is a structure.


    if(!*phone[loc].name) break;

    Help a learner like me please!!!!
    ---Programming is like roaming, you never know where you'll end at------

    If 'here' is pronounced as 'hear', why 'there' isnt pronounced as 'dear'??

    [email protected]

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    1. getche returns a character, but you don't need to write the comma's.
    In stead you can use the integer value of the character (you need to look that up in the ASCII table).
    For example, you can find the character '1' in the ASCII table on index 31 (and '5' on index 35).
    Code:
    while(i<31 || i>35); // this also works
    2. the return i - '0' means return 32 (character '2') - 30 (character '0') when someone enters the character 2.

    3. *phone[loc].name is the same as phone[loc].name[0]
    so you check if the first character in the character array is a null character.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM