-
Dynamic Arrays?
Hey.
Is there a relativly simple way to make a dynamically sized array?
I'll explain the problem.
I want to write a program that calculates the reisitences of any number of inputted resistors, and to make life easier (so i thought) i decided to use a resistance array, that would be made one unit bigger each time my input loop is run.
pseudo code goes like this:
Code:
double resistance[]
for(int i;input !=0;i++)
{
"Input Resistance" +i
scan resistance[i]
}
then afterwards all the calculation is done in a similar for loop on the array.
the problem is that I'm finding it difficult to code a dynamic array and am at a loss for what to do.
Any help would be greatly appreciated.
Thankyou for your time.
-
Nope. You'll need something like a linked list, or realloc.
Quzah.
-
> I want to write a program that calculates the reisitences of any number of inputted resistors
In series, or in parallel?
It's pretty easy to keep the current resistance, then add in the new resistance without the need to store all the prior inputs.
But if that's what you must do, then do as Quzah suggests.
It's a good idea to make sure the code works with a fixed length array first.