Getting user input into program in the form of int or char

This is a discussion on Getting user input into program in the form of int or char within the C Programming forums, part of the General Programming Boards category; I need help getting user input this is the best I can think of: Code: int drug_choice_selection; char drug_choice[100]; printf("How ...

  1. #1
    Registered User
    Join Date
    May 2012
    Location
    Milwaukee
    Posts
    26

    Getting user input into program in the form of int or char

    I need help getting user input this is the best I can think of:
    Code:
    int drug_choice_selection;     
          char drug_choice[100];
          printf("How Much? \n");
                     
          fgets(drug_choice, sizeof(drug_choice), stdin);
          sscanf(drug_choice, "%d", &drug_choice_selection);

    If I wanted to extract a single char from user input what is the easiest way to do it?

    1.Choose a number/char
    2. enter it...
    3. use it in the program



    Thanks

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    2,273
    getchar()

    [edit] This would be a good time to get acquainted with the ASCII table, if you haven't already.
    Last edited by Matticus; 07-19-2012 at 08:54 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing out char elements in an array from user input
    By hencherz in forum C Programming
    Replies: 11
    Last Post: 02-23-2012, 07:48 AM
  2. Want User Input but Program Ends
    By completenewbieu in forum C Programming
    Replies: 5
    Last Post: 08-29-2011, 04:10 PM
  3. Replies: 3
    Last Post: 10-12-2010, 01:40 PM
  4. Replies: 4
    Last Post: 04-03-2008, 09:07 PM
  5. user input and program design
    By Chaplin27 in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2005, 08:53 AM

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