scanf

This is a discussion on scanf within the C Programming forums, part of the General Programming Boards category; Ok, now I need to read in input through the keyboard. I need to read in for example "mult 40.3" ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    14

    scanf

    Ok, now I need to read in input through the keyboard. I need to read in for example "mult 40.3" and then I need to parse it to get the mult as a string to convert to uppercase and an double for 40.3 any ideas on how to do this. Should I use scanf or can I even use it or is there something else to use?

    Thanks

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    14
    I also need to know when the input is finsished but I can not use ctrl c it has to been inside the loop.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    One way is to use fgets() followed by sscanf().
    Code:
       char a[80];
       char b[80];
       double num;
    
       fgets(a,80,stdin);
       sscanf(a,"%s %lf",&b,&num);
    You can do this in one step with scanf(), but it's not as safe.
    To convert to uppercase, use toupper() in a for-loop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf() consideres useless
    By Snafuist in forum C Programming
    Replies: 15
    Last Post: 02-18-2009, 08:35 AM
  2. Help with a basic scanf procedure.
    By killpoppop in forum C Programming
    Replies: 9
    Last Post: 11-03-2008, 04:39 PM
  3. Replies: 2
    Last Post: 02-20-2005, 01:48 PM
  4. Scanf and integer...
    By penny in forum C Programming
    Replies: 3
    Last Post: 04-24-2003, 07:36 AM
  5. scanf - data is "put back" - screws up next scanf
    By voltson in forum C Programming
    Replies: 10
    Last Post: 10-14-2002, 05:34 AM

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