Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: meyumraaj on June 10, 2015, 03:02:44 pm

Title: array elements fills with random value after 10th element codeblocks 13.12
Post by: meyumraaj on June 10, 2015, 03:02:44 pm
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 :)

Title: Re: array elements fills with random value after 10th element codeblocks 13.12
Post by: stahta01 on June 10, 2015, 03:41:57 pm
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://forums.codeblocks.org/index.php/topic,9996.0.html)
http://wiki.codeblocks.org/index.php?title=FAQ (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 (http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F)

Tim S.
Title: Re: array elements fills with random value after 10th element codeblocks 13.12
Post by: stahta01 on June 10, 2015, 03:48:09 pm
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 (http://wiki.codeblocks.org/index.php?title=Debugging_with_Code::Blocks)

Tim S.
Title: Re: array elements fills with random value after 10th element codeblocks 13.12
Post by: meyumraaj on June 10, 2015, 04:26:42 pm
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 ???
Title: Re: array elements fills with random value after 10th element codeblocks 13.12
Post by: oBFusCATed on June 10, 2015, 07:09:29 pm
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.
Title: Re: array elements fills with random value after 10th element codeblocks 13.12
Post by: meyumraaj on June 11, 2015, 10:30:38 am
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.
Title: Re: array elements fills with random value after 10th element codeblocks 13.12
Post by: oBFusCATed on June 11, 2015, 09:51:55 pm
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.
Title: Re: array elements fills with random value after 10th element codeblocks 13.12
Post by: raynebc on June 12, 2015, 12:41:11 am
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.
Title: Re: array elements fills with random value after 10th element codeblocks 13.12
Post by: meyumraaj on June 12, 2015, 08:55:50 am
It was just my confustion

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

Thank You Very Much  oBFusCATed and raynebc :D