Initialization to zero suddenly changes value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • simmol
    New Member
    • Dec 2008
    • 2

    Initialization to zero suddenly changes value

    Hi,

    I'm running a simulation over time and I'm having trouble with arrays in my C program. An array element that has been initialized to zero suddenly changes value to 13 after a few time points, and surprisingly, this only happens in some runs. If I print out values from different parts of the program, I can clearly see the value changing.

    I am not using dynamic memory allocation, so I'm not sure why I see this strange behavior. Has anybody seen such behavior before and do you have any idea what could be causing the problem?

    I am stuck at this point and I'm not sure how to proceed. Any suggestions/advice will be greatly appreciated.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Without seeing any code I guess/suspect that some char[] is overwritten and causes a worm (too many chars are written to that array); but I could very well be wrong though.

    kind regards,

    Jos

    Comment

    • simmol
      New Member
      • Dec 2008
      • 2

      #3
      The code is very long..I could e-mail it to you.

      Thanks!

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        You could try posting the parts of the code that you suspect.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Look at the variables that are defined just before that mysteriously changing variable in the same scope; especially suspect the char[] variables; check the code that manipulates those variables. The error is most likely somewhere in that code.

          kind regards,

          Jos

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            Almost certainly you have a pointer error and I suspect your array handling code is scatttered throughout the program. The first thing I would do is write a series of functions to manage that array and call those functions as needed elsewhere in the program.

            Comment

            Working...