Dynamic Arrays?

This is a discussion on Dynamic Arrays? within the C Programming forums, part of the General Programming Boards category; Hey. Is there a relativly simple way to make a dynamically sized array? I'll explain the problem. I want to ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    1

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

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


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,335
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 10:18 AM
  2. Replies: 16
    Last Post: 01-01-2008, 03: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21