#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    23
    Rep Power
    0

    Printing a structure


    print a structure.
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,220
    Rep Power
    2222
    "%s" specifies a string, not a decimal integer (which would instead be "%d"). So you're forcing printf to treat those three decimal values as pointers to strings -- ie, as memory addresses. Memory addresses that low would most definitely be in an area of memory that's reserved for the operating system, so the operating system protects itself from you by terminating your program with extreme prejudice. For that matter, trying to access any memory location that's not assigned to you, including those of other processes, will also cause your program to crash (the error code / message should say something about an "access error" or a "segmentation fault", AKA "segfault").

    Use the proper format specifiers in printf instead.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    23
    Rep Power
    0
    Thanks dwise, I swear I started off with %d but I changed it because I was getting a compile error earlier. Obviously it was because of something else. Thanks again.

IMN logo majestic logo threadwatch logo seochat tools logo