Integers value is being wrongly altered

This is a discussion on Integers value is being wrongly altered within the C Programming forums, part of the General Programming Boards category; For some reason, the value held within my integer is being altered by this one function. I've been able to ...

  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 08:40 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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-30-2008, 12:35 AM
  4. Replies: 8
    Last Post: 10-24-2005, 12:26 PM
  5. Replies: 6
    Last Post: 08-04-2003, 11:57 AM

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