Thread: passing arrays through functions

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    4

    passing arrays through functions

    hi.. i'm been trying to pass an array from one function to the next and my complier doesn't like it for some reason... i've tried a number if different things, like
    function(array[]),
    function(array[x]) and
    function(array)... nothing works.. any chance someone out there can help ?

    thanks

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Code:
    void foo(char a[])
    {
      /* do something */
    }
    
    
    // Elsewhere:
    char name[50];
    foo(name);
    Post more code if you're stilling having trouble.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    or if it is a multidimensional array:
    Code:
    void foo(array[][50])
    {
         //function body
    }
    
    //....and to call it,
    
    char array[25][50];
    foo(array);
    axon

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  4. #4
    Registered User Xei's Avatar
    Join Date
    May 2002
    Posts
    719
    Depending on the use:
    Code:
    void foo(byte *Array, int Length)
    {
         //Do stuff here like...
         GetWindowText(hWnd, Array, Length);
         //Or...
         FillMemory(Array,"\0",Length);
         //Or...
         Array = (byte *)calloc(Length, sizeof(byte));  //Unlikely ;)
         free(Array);  //Also Unlikely.
    };
    Last edited by Xei; 04-08-2003 at 05:44 PM.

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    4

    thanks

    ahh.. thanks for helping me out.. the thing actually works now..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Manipulating Character arrays in functions.
    By kbro3 in forum C++ Programming
    Replies: 11
    Last Post: 08-16-2008, 02:24 AM
  2. Replies: 2
    Last Post: 07-03-2008, 11:31 AM
  3. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  4. Functions returning char arrays
    By turmoil in forum C Programming
    Replies: 3
    Last Post: 05-27-2003, 01:43 AM
  5. Passing multidimensional arrays to functions
    By maxthecat in forum C Programming
    Replies: 3
    Last Post: 12-22-2001, 03:58 PM