Thread: Error consistency checking

  1. #1
    Registered User
    Join Date
    Mar 2003

    Post Error consistency checking with converting double into string

    Last edited by Tibo; 03-28-2003 at 02:46 AM.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    So, here's an example of the input:

    blah 20 10 100503 location

    How many spaces are there? I see 4. So why are you doing:
    >>if (count != 5)

    And this:
    >>if (startkm > endkm)
    >>Invalid. Start km must be greater than end km
    You're test doesn't match your error message.

    The variables startkm and endkm are double, and as such, sscanf() and fprintf() will need to be told they're %lf, not %d as you currently have.

    If you really want to use sscanf() to grab the two numbers from the input line, I suggest you do it like so:
    if (sscanf(line, "%*s %lf %lf", &startkm, &endkm) != 2)
      fprintf ("Two numbers were not read in\n");
      /* Handle error */
    You might also want to investigate grabbing the string inputs at the same time (name/date/location)

    And code tags use [] brackets on these forums, not <>
    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. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Overflow and range checking for mul/div
    By Elysia in forum C++ Programming
    Replies: 28
    Last Post: 06-06-2008, 02:09 PM
  3. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  4. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  5. Problems about gcc installation
    By kevin_cat in forum Linux Programming
    Replies: 4
    Last Post: 08-09-2005, 09:05 AM