Thread: Dynamic Arrays?

  1. #1
    Registered User
    Join Date
    Oct 2006

    Post Dynamic Arrays?

    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:
    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.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Nope. You'll need something like a linked list, or realloc.

    Hope is the first step on the road to disappointment.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > 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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating and freeing dynamic arrays
    By circuitbreaker in forum C++ Programming
    Replies: 8
    Last Post: 02-18-2008, 11:18 AM
  2. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  3. Dynamic (Numeric) Arrays
    By DavidB in forum C++ Programming
    Replies: 5
    Last Post: 05-03-2006, 07:34 PM
  4. dynamic arrays and structures
    By godofbabel in forum C++ Programming
    Replies: 1
    Last Post: 10-13-2002, 03:45 PM