Thread: A Problem

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    5

    A Problem

    Hi,

    how can i get input from a user (float) continuously and exit the loop if something not a number is entered

    for example,

    1 2 3 4.7 5 6 7 8 9
    3 4 5
    1 2 3 4 5 6.6

    will kepp the program to get the number and process them after ENTER is press

    But

    1 2 3 a

    will process the first 3 numbers and stop the top the program

    my code:


    scanf("%f", &num);
    if (isalpha(num) != 0)
    {
    x1 = num;
    }
    else
    {
    display_area(y);
    exit();
    }


    but it doesn't work
    because num is not scaned if it's not a float

    what should i do, thanks a lot

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    FAQ
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM