Error Checking...???

This is a discussion on Error Checking...??? within the C Programming forums, part of the General Programming Boards category; Hey Guys... and Gals. I am new to this programming thing and I was wondering if anyone can help me. ...

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

    Error Checking...???

    Hey Guys... and Gals.
    I am new to this programming thing and I was wondering if anyone can help me. I have to error check a program that I am writing and make sure it will only accept the integers from 0-99.
    It cannot accept alpha characters nor can it accept float or double values... my problem is with the double values. I get it to not accept alpha by using something like

    while((some_variable<100)&&(some_variable>=0)&&(so me_variable!=EOF)) {

    but it will just convert floats to integers and is killing me.. Thanks.

  2. #2
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    I'm sure there's an easier way, but I'd read everything into a character array using a while loop and getch(), validate the input, and if it's valid increment the array's index and move on until you get an enter (ASCII code 13), and run atoi() on your array.

  3. #3
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    Originally posted by -KEN-
    ...until you get an enter (ASCII code 13), ...
    Cann't he use '\n'?
    none...

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    99
    Why not look into the ctype header file for is...() functions? Those several functions should shorten some aspects of your code.

  5. #5
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    Originally posted by ammar
    Cann't he use '\n'?
    You'd think so, wouldn't you? But I was writing the reply while thinking about a function I'd written a few days ago for a program in my C++ class that did exactly what he wanted (validating input and error checking), and I tried checking for '\n' and found that it wouldn't accept it, nor any of the other monickers for a newline. I had to settle for the ASCII code...

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    53

    I'm confused...

    I don't know what fgets is???? is there another way.. Thanks for the help thus far.

  7. #7
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,659
    C'mon man, make some effort here. fgets() is in every C textbook. Look it up please. Finally, study Salem's fine code and actually try to understand it. Also, you can of course say if b[x] == '.' to test for floating point input....



    ITSA
    Socket Library!

Popular pages Recent additions subscribe to a feed

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