Author Topic: array elements fills with random value after 10th element codeblocks 13.12  (Read 2296 times)

Offline meyumraaj

  • Single posting newcomer
  • *
  • Posts: 5
I am a new user to Codeblocks and beginning to learn C; I have this problem since the beginning

Whenever i have array with more then 10 elements and while i try to iniatilize the element value to 0 using a loop; after 10th element all the array element fills with random value. I have attached the snapshot for reference.

Any suggestion would be appreciated :)


Offline stahta01

  • Lives here!
  • ****
  • Posts: 6666
    • My Best Post
Edit: Most debuggers and likely CB does the same shows the value before the line in debugger is executed!
I suggest doing a break point after the line.


Read the Rules and the FAQs.
http://forums.codeblocks.org/index.php/topic,9996.0.html
http://wiki.codeblocks.org/index.php?title=FAQ

Edit2: Post a build log and your code on a site that teaches how to program.
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F

Tim S.
« Last Edit: June 10, 2015, 03:48:30 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6666
    • My Best Post
Please read the debugger info it might help.
Edit: Sorry, I misread your question; did NOT realize it was on how to use the debugger instead of on how to code.

http://wiki.codeblocks.org/index.php?title=Debugging_with_Code::Blocks

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline meyumraaj

  • Single posting newcomer
  • *
  • Posts: 5
I am using codeblocks in windows 8. I have a doubt that if there is some tweak/setting/config i have to adjust in codeblock.

somehow array longer then 10 element is not being initialized.

How could debugger have something to do with it ???

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12081
    • Travis build status
This is a bug in the debugger plugin.
Do you see the first line in your watches windows - 0 <repeats 11 times>?
This means that the debugger is trying to be smart and tells us that this array has 11 zeroes at the first 11 elements.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline meyumraaj

  • Single posting newcomer
  • *
  • Posts: 5
Its not the debugger which is initializing the array values to 0

For Loop in the code is initializing value of 0 in each and every elements in the array but when for loop reached 10th element all the array values  goes back to random values.

The problem is; I can't initialize array elements value to 0.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12081
    • Travis build status
I think you're wrong here.

One easy way to find out is to add another loop after your initialization loop that will print the values of the array on the screen.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline raynebc

  • Almost regular
  • **
  • Posts: 212
He's being misled by it saying counts[0] is a series of 11 zeroes and that counts[1] is a nonzero value.  If the bug that oBFusCATed mentioned is that it should instead read that counts[0] is 0 repeated 11 times and that counts[11] is nonzero, that would seem to be the cause for confusion.

Offline meyumraaj

  • Single posting newcomer
  • *
  • Posts: 5
It was just my confustion

Array was initialized properly and debugger was saying 11 times 0 :)

Thank You Very Much  oBFusCATed and raynebc :D