Thread: Integers value is being wrongly altered

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    36

    Thumbs up Integers value is being wrongly altered

    For some reason, the value held within my integer is being altered by this one function. I've been able to narrow the bug down to this one function by printing the contents of this integer step by step as the procedural code executes.

    This integer stores the number of lines in my lottery.dat file which is 1185, however after this function is being invoked, the value is changing to 1024, this function doesn't even use this integer variable in question, this is making it very difficult for me to comprehend the problem and the reason for it occuring.

    Any feedback would be appreciated.

    Value: 1185
    BUG after 'setAlphaPosition', Value: 1024
    The change in the integers value is occuring when setAlphaPosition is called with two parameters being passed to it, none of which are the integer in question.

    Edit, please see link, lack of word wrap in code tags stretches this thread.
    Code:
    http://www.queslib.com/err/lotteryProg.c
    Last edited by Cero.Uno; 04-26-2008 at 07:40 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Code:
    alphaPos[sizeof(alphaPos)] = '\0'; // say goodbye to the byte stored after alphaPos!
    Fixed your comment.

    Note that string literals (such as "6th") end in a \0 character by definition.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    36
    Quote Originally Posted by tabstop View Post
    Code:
    alphaPos[sizeof(alphaPos)] = '\0'; // say goodbye to the byte stored after alphaPos!
    Fixed your comment.

    Note that string literals (such as "6th") end in a \0 character by definition.
    awesome dude, thank you so much, saved me best part of next two hours

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  2. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 02:24 PM
  3. Integers into array.
    By livestrng in forum C Programming
    Replies: 10
    Last Post: 10-29-2008, 11:35 PM
  4. Replies: 8
    Last Post: 10-24-2005, 11:26 AM
  5. Replies: 6
    Last Post: 08-04-2003, 10:57 AM