bagaimana caranya passing array di C++ ?

Published 18 March 05 04:54 AM | kukuhtw
mentok lagi nih...!@#!#!...... coba tanya lewat blogs deh..siapa tahu ada yang mau bantuin....
 
*************************************************
I'm currently using visual studio c++.net to develop QualComm BREW Gaming Applliation,
I have code like below this
C / C++ Code:
void SimpleBall_DrawScreenBlocks(SimpleBall * pApp)
{
  AEERect rect;
  int irow,icol,nIndexBlocks;
  short  idBlocksIndex;
             int mapBlocks[10][5]={1,1,1,1,1,
        1,1,0,1,1,        
        1,1,0,1,1,
        1,1,0,1,1,
        1,1,1,1,1,
        1,1,1,1,1,
        1,1,1,1,1,
       1,1,1,1,1,
        1,1,1,1,1,
        1,1,1,1,1,
      };
  
  boolean bHits;
  idBlocksIndex = 0;
    
  // coding for draw screen below this  

}
I'd like to create method of SimpleBall_ReadMapBlocks that could be passing from method of SimpleBall_DrawScreenBlocks(SimpleBall * pApp), but i don't know how . It could be seen like this

C / C++ Code:
void SimpleBall_DrawScreenBlocks(SimpleBall * pApp)
{  
  AEERect rect;
  int irow,icol,nIndexBlocks;
  short  idBlocksIndex;
             int mapBlocks[10][5]=SimpleBall_ReadMapBlocks(?????)
}
I don't know to how to create SimpleBall_ReadMapBlocks's method
 
Share this post: | | | |

Comments

# kukuhtw said on March 18, 2005 08:46 PM:

Kenapa gak di pass-by-reference aja array of integers nya? Lantas di modify di SimpleBall_ReadMapBlocks?

void SimpleBall_DrawScreenBlocks(SimpleBall * pApp)
{
AEERect rect;
int irow,icol,nIndexBlocks;
short idBlocksIndex;
int mapBlocks[10][5];

// pass array by ref
SimpleBall_ReadMapBlocks(mapBlocks);
}

void SimpleBall_ReadMapBlocks( int arr[][5] )
{
arr[0][0] = 0;
arr[0][1] = 1;
// dan seterusnya...
}

Jangan lupa untuk passing multi-dim array ke function, jumlah kolomnya musti ditulis juga!

Happy coding,
regards,
Z.

# kukuhtw said on March 22, 2005 10:53 PM:

Zedi ...Thanks buat saran2nya....
Akhirnya aku retouch lagi codingnya menjadi

void SimpleBall_DrawScreenBlocks(SimpleBall * pApp)
{
AEERect rect;
int irow,icol,nIndexBlocks;
short idBlocksIndex;
int mapBlocks[JUMLAHCOLUMN][JUMLAHBARIS];

boolean bHits;
idBlocksIndex = 0;
SimpleBall_ReadMapBlocks(pApp, mapBlocks);

// coding selanjutny disini
}

void SimpleBall_ReadMapBlocks(SimpleBall * pApp, int arr[JUMLAHCOLUMN][JUMLAHBARIS])
{
arr[0][0] = 1;
arr[0][1] = 1;
arr[0][2] = 1;
arr[0][3] = 1;
....dstnya.....
}

Nah sekarang aku mau pindah data-datanay ke file TXT....
Aku coba tulis begini

void SimpleBall_ReadMapBlocks(SimpleBall * pApp, int arr[JUMLAHCOLUMN][JUMLAHBARIS])
{
IFile * pIFile = NULL;
FileInfo fi;
IFileMgr * m_pIFileMgr;
char * File_Data = NULL;
char szFileName[50] = {0} ;
char data[100]= {0} ;
ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_FILEMGR,(void **)&m_pIFileMgr);
pIFile = IFILEMGR_OpenFile(m_pIFileMgr, "test.txt", _OFM_READ);

IFILE_GetInfo(pIFile, &fi);
if (IFILE_Seek(pIFile, _SEEK_START, 0) == SUCCESS)
{
IFILE_Read(pIFile, data, TOTAL_BLOCKS);
File_Data = (char*) data;
}

IFILE_Release(pIFile);
pIFile = NULL;
IFILEMGR_Release(m_pIFileMgr);
m_pIFileMgr = NULL;

// Coding ini menggunakan platform BREW 3.00 Sdk Visual C++.Net
// variabel File_Data didapat dari file test.txt...
// File test.txt isinya begini
// 1,1,0,1,0,1,1,1,1,1,... danseterusnya...
}

Pertanyaannya...bagaimana ya menterjemahkan variable File_data ke dalam
Variabel
arr[0][0] = ambil dari variable file_data ...??;
arr[0][1] = ambil dari variable file_data ...??;
arr[0][2] = ambil dari variable file_data ...??;

# kukuhtw said on May 7, 2006 04:24 PM:

bursa