0 Clark Alaan · April 13, 2015
This is a decent-sized project question. Just warning you.
Here's a download of my .cbp project folder(zipped): https://drive.google.com/file/d/0B9ho5Xaxx0gKZFJTZXBFYTNGVmM/view?usp=sharing

It is a simplified electric circuit simulator.

But what I really want to ask is in this snippet from circuits.c :

Everytime this code runs, specifically on line 16 and 42 to 49, it returns some huge number, and it also repeats way more than I assign it to happen. I really cannot see what I am doing wrong and would like some help.

I've tested almost every part of the code and this is practically the one that has the main problem(the effective voltages and effective currents also have a problem, but I can't move forward until I solve this one first) and it just blows my mind. I don't understand why it's popping out those huge numbers at all. Is there any for-loop peculiarity that I am just simply missing the point of?

I am not asking for entire code revisions, only point out I have been doing wrong and what I can do to fix it.
Please help. Thank you.

Post a Reply


Oldest  Newest  Rating
0 Yaron X · April 13, 2015
Can't see anything obvious except that in function get_ladder_resistance() the variable 'i" is not defined and you probably defined it somewhere as a global.

I created the following main() function and the output was as shown below. Looks right?

int main(int argc, char* argv[] )
double restarr[] = {1,2,3,4,5};
double result;

result = get_effective_resistance(restarr, 1, 5);
printf ("result:%f\n", result);
result = get_effective_resistance(restarr, 2, 5);
printf ("result:%f\n", result);
result = get_effective_resistance(restarr, 3, 5);
printf ("result:%f\n", result);
return 0;

ResistNO. @case3
DEBUGladder: 5
DEBUGladder: 2
DebugPH: -1
0 c student · April 13, 2015
0 Clark Alaan · April 13, 2015
@Yaron H
I defined it in line 32. Unless I am somewhat mistaken about that. Just out of curiosity though, what did you define the variable "i" as? The answer for the ladder topology(which is '3') is wrong though. I'll take a look into it tomorrow it's pretty late here atm.

@c student
Thank you ALOT. I've been looking for an equivalent of try and catch of Java in C for a while.
  • 1



One of the most popular languages of all time.

Bucky Roberts Administrator