Question:

I want to use getchar function in my c program but i dont know how to use...please help, thanks

by  |  earlier

0 LIKES UnLike

i would like to use it in decision making,in asking yes or no..

 Tags:

   Report

1 ANSWERS


  1. Here is an example program on how to ask the user with getchar:

    #include <stdio.h>

    int main() {

    int retry;

    int key;



    do {

    retry = 0;

    printf("Shall I say hello (y/n)? ");

    key = getchar();

    switch(key) {

    case 'y':

    printf("Hello!\n");

    break;

    case 'n':

    break;

    default:

    retry = 1;

    printf("Please enter y or n!\n");

    }

    } while(retry == 1);



    return 0;

    }

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.