Thread: arrays, functions, HELP

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    23

    arrays, functions, HELP

    Code:
    i have another question on arrays
    if the program is to scanf and read in values in this form:
    
    30.0 50.4 60.0
    40.9 69.9 30.9
    
    ...hence
    x   y   z format
    
    
     and the list can go to no more than 100, how would i declare and add three parallel arrays ?
    
    i then have a function that reads in these numbers to caluculate, say x*y*z for row 1 then row 2 and so on..and then add the total. how would i change this function as to alter the reading loop so that it reads into my data structure, allowing it to be repeatley manipulted?
    any genius out there that could give me an outline for this?
    
    so far i have written the program without using arrays and simply using 2 functions-one from the main that scans in the values and another in the format
    
    double
    mult_i(double x double y  double z){
       body
    return soemthing;
    }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Have you not already started a thread on a very similar subject?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    You mean a table of <unknown>x3 doubles? Try to declare an array of <unknown> arrays of 3 doubles. Then try to access the first value in the first array. It will go.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Brafil View Post
    You mean a table of <unknown>x3 doubles? Try to declare an array of <unknown> arrays of 3 doubles. Then try to access the first value in the first array. It will go.
    No. You can't declare an array without a size specifier and actually expect to use it to infinity. That would be like declaring a pointer, not making it point anywhere, and assuming it is pointing at limitless memory.


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

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    So perhaps you could declare 3 arrays of type double, and make the size of each one 100.

    Then, as you add the data into the array, just keep a count so you know where the end of the legitimate data is.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. functions using arrays
    By trprince in forum C Programming
    Replies: 30
    Last Post: 11-17-2007, 06:10 PM
  2. Passing arrays of pointers into functions
    By ashley in forum C Programming
    Replies: 5
    Last Post: 01-13-2007, 06:48 PM
  3. storage class, arrays, functions and good layout
    By disruptivetech in forum C Programming
    Replies: 4
    Last Post: 12-02-2005, 02:34 PM
  4. functions and arrays
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 03-14-2002, 09:57 AM
  5. elements of arrays; functions
    By sballew in forum C Programming
    Replies: 6
    Last Post: 09-03-2001, 01:48 AM