Reading an error in a .dat file

This is a discussion on Reading an error in a .dat file within the C Programming forums, part of the General Programming Boards category; For an assignment I have to read a .dat file and load it into a linked list then sort it. ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    127

    Reading an error in a .dat file

    For an assignment I have to read a .dat file and load it into a linked list then sort it.

    My problem is that I'm not sure how to check that the information in the file is correct.

    The example we have it that there is a field with 12..34 instead of 12.34 and so it should return an error message. I am using a float as this value.

    Any direction/help would be great.

    Thanks.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Read the value as a string and then validate it with something like strtod.
    My best code is written with the delete key.

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I think when you give strtod "12..34" it just reads out 12, because it stops on the first illegal character.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,758
    At least it points to where it stopped at so you can check it. Unlike some other functions.

  5. #5
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Yeah, it's the best standard function for this. Also you could make your own functions but with doubles, it is much harder to do than with integers.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Also you could make your own functions but with doubles
    Uh, yea. Totally not worth it.
    My best code is written with the delete key.

  7. #7
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    But I like messing with these things - they are good practice.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >But I like messing with these things - they are good practice.
    We've been through this before. I don't care how you practice, but please don't use it as an excuse.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 11:12 PM

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