Thread: trouble printing linked list

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    16

    Thumbs down trouble printing linked list

    thank you for helping
    Last edited by deathrattle; 12-02-2008 at 07:57 PM.

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    That's because you're not reading them properly . Do a bit of error checking in your fscanf() and you'll probably find out it's not reading everything you want.

    For example (just match the colours up to see what's read):

    Code:
    fscanf(fPIn, "%s%s%d%d%s%d%d", ...);
    Peter Griffin   1 111-11-1111 May 9, 1965
    The underlined part isn't read (By this call anyway), thus those numbers remain uninitialized (or random as you call them).

    Also, you have a buffer overflow (well a potential one), for example what if someone has name bigger than char fName[MAX];? Perhaps use fgets() and sscanf()
    Last edited by zacs7; 12-02-2008 at 06:21 PM.

  3. #3
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Look at this:
    Code:
    fscanf(fPIn, "%s%s%d%d%s%d%d"
    and this:
    Code:
    Peter Griffin   1 111-11-1111 May 9, 1965
    and note that a ',' is not a whitespace.

    Possible solutions is not putting the , in the file or doing something like:
    Code:
    fscanf(fPIn, "%s%s%d%d%s%d,%d"
    which migh work (never seriously using scanf). But the generally that way you skip specific characters.

    edit: or probably you need be
    Code:
    fscanf(fPIn, "%s %s  %d %d-%d-%d %s %d, %d"

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Clicky

    Simply use this in conjunction with your current code to print dates in a readable format.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help sorting a linked list. Beginner
    By scarlet00014 in forum C Programming
    Replies: 1
    Last Post: 09-27-2008, 06:16 PM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Problem with linked list ADT and incomplete structure
    By prawntoast in forum C Programming
    Replies: 1
    Last Post: 04-30-2005, 01:29 AM
  5. doubly linked list error.
    By noob2c in forum C++ Programming
    Replies: 12
    Last Post: 09-01-2003, 10:49 PM