Thread: arrary into function

  1. #1
    Cipr0
    Guest

    arrary into function

    I am trying to pass a 2d array into a function but it keeps giving me errors. Can someone post some source of what the function will look like and how to call it.

    Thanks
    Cipr0

  2. #2
    Unregistered
    Guest
    I do it like this. This example is with a 2D char array.

    Code:
    void fillArray( char (*aBuffer)[MAX_ROWS]){
          int c =5;
      /* accessing individual elements.  Should really ensure
          that i am not accesing elements passed max_rows here. 
         e.g.  if c<max_rows.  But this is only example only */
    
       strcpy(aBuffer[c], "Hello there");
    
      /* filling with a for loop */
       for(c=0;c<MAX_ROWS;c++)
          strcpy(aBuffer[c], "Some text");
    
       etc...
         
    
    }
    Cheers,
    G'n'R

  3. #3
    Unregistered
    Guest
    oh and you call it like this. sorry....

    Code:
    #define MAX_ROWS 1000
    
    main(void){
    
      char stringArray[50][MAX_ROWS];
    
      fillArray(stringArray)
    
      etc...
    }
    There are other ways to prototype the fillArray function. I think you can also do this. But no sure...

    Code:
    void fillArray( char aBuffer[][MAX_ROWS]){
       etc....
    }


    G'n'R

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM