I can't change the value of my array elements

0 Clark Alaan · April 14, 2015
Sorry, I asked the same question in StackOverflow. Hopefully, you guys wouldn't mind. >.<



Post a Reply


Oldest  Newest  Rating
0 c student · April 14, 2015
use the assert function to test.  if that doesn't help, please paste your entire code somewhere so we can have a look.
0 Clark Alaan · April 14, 2015
main.c  -> http://pastebin.com/Yc2Y7T51
@Line of interest: 78

get_input.c -> http://pastebin.com/JQHFUiHp
@Line of interest: 123
get_input.h -> http://pastebin.com/AeQSax8s

Someone just posted in StacKOverflow that the code worked in IDEone. Is it possible that Code:Blocks is just screwing with me?

I probably will feel like a total idiot if that's true.
0 c student · April 14, 2015
i'm not sure about code:blocks, i've never used it before.  maybe there's a compile error or something that code:blocks didn't pick up.  use the assert and write up a test function.
0 Clark Alaan · April 15, 2015
Sorry, I'm not exactly sure how to use assertion on a = operator. I've tried using
assert(resistor_values[0] == 1);

after the for-loop and I inputted the first element to be 1 in the program, and assert did not crash the program. Yet when I print it out later it's zero. I'm going to download another IDE and try running it there. I'm using Win7 and now I suddenly wish I didn't uninstall my Ubuntu.
0 c student · April 15, 2015
assert (resistor_values[i] == /* whatever you expect it's value should be */);

you can also go into your get_resist_value function and test the following:

assert ((strncmp (input, "Infinity", 9) == 0) || (strncmp (input, "infinity", 9) == 0));


assert (placeholder == INFINITY);

a quick question: are you manually entering into input in get_input.c:132?
if you are, maybe it'd help to look at http://linux.die.net/man/3/fgets
0 Clark Alaan · April 16, 2015
Thanks for the reply. I found out why my assertion was not working(I was an idiot and made it set a value rather than check a value, weirdly enough the code I wrote here was correct). I have tried your suggestions and the program does not crash within the function. Something weird is indeed happening with my array that I do not have a single clue as to why it is happening. There seems to be nothing wrong with my code, so I really don't understand what kind of wizardry is not making it work.

Maybe MinGW compilers for windows have something wrong with them? This is fairly simple code though, if it doesn't compile something like this who knows what it can't compile properly? Highly doubt this is the case however. Seeing as people do see it as reliable. I'm planning to get Cygwin and hope that that works.

I also got Eclipse CDT and DL'd a 32-bit MinGW as I use Win7 Home Basic 32-bit. I saw a bunch of errors that Code:Blocks did not show and now managed to resolve, however the array element assignment still does not work at all. Seeing as this is an integral part of my code, I'm pretty much stumped in every which way. I really wish I didn't uninstall my Ubuntu now.

Recently read this topic in C++ forums:

Well, I'm now sure that I seriously should uninstall Code:Blocks and Eclipse CDT and move on to something like CLion or Visual Studio. Though Visual Studio's interface is somewhat intimidating for me(Not sure why).
0 c student · April 16, 2015
Which situations did you test the function under?

MinGW works fine for me - my setup is basically Sublime Text + MinGW, nice and simple and clean.  I don't really recommend VS.
0 Clark Alaan · April 19, 2015
I resolved it by using Dev C++... Really odd. Probably will uninstall Code:Blocks and Eclipse CDT now. As for MinGW, I'll probably keep it... and I might consider getting Cygwin along with a much simpler text editor to work with such as Notepad++. Probably the safest and most reliable way to work I presume.

Thanks for all the help c student.
  • 1



One of the most popular languages of all time.

Bucky Roberts Administrator