Thread: getchar() and while loops

  1. #1
    back? dbaryl's Avatar
    Join Date
    Oct 2001
    Posts
    597

    getchar() and while loops

    I have the following code:
    Code:
    do
    {
      printf("\nEnter fraction %d: ", i + 1);
      scanf("%d %d/%d", &frac[i].whole, &frac[i].num, &frac[i].den);
      printf("\nYou entered: %d %d/%d", frac[i].whole, frac[i].num, frac[i].den);
    
      printf("\nEnter 'Y' to re-enter last fraction [anything else to continue]: ");
      rewind (stdin);
      //check = getchar();
    }
    while (getchar() == ('y' || 'Y'));
    now, obviously, something's wrong with
    >>while (getchar() == ('y' || 'Y'));

    I wanted to do this without assigning the value returned by getchar to an int or char, is ther a way to do this?
    This is my signature. Remind me to change it.

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Code:
    while(toupper(getchar()) == 'Y')

  3. #3
    back? dbaryl's Avatar
    Join Date
    Oct 2001
    Posts
    597
    Thanks a lot, I hadn't thought of that.
    This is my signature. Remind me to change it.

Popular pages Recent additions subscribe to a feed