|
int a = 17;<br />
int* (*pi)[32] = new int* [32][32]; <br />
pi[31][31] = &a;<br />
cout << *pi[31][31] << endl;<br />
delete [] pi;
|
|
|
|
|
Declare as such:
<br />
int **myArray<br />
These ways to allocate them
<br />
myArray = new[] int [rows][cols];<br />
or
<br />
myArray = new[] int[rows * cols];<br />
<br />
myArray = (int *) malloc(sizeof(int( rows * cols)));<br />
<br />
int counter<br />
myArray = new[] int* [rows]<br />
for (counter = 0; counter < rows; counter++)<br />
{<br />
myArray[counter] = new[] int [cols];<br />
}<br />
don't forget to check if the memory has been allocated (if(myArray) ). This presents you using and dereferencing a NULL pointer.
Good luck,
Alton
|
|
|
|
|
I like to access the data with the double bracket-style syntax, data[x][y], so this is what I do :
void **Allocate2DArray( int xdim, int ydim, int itemsize )
{
int x;
void **data = (void **)calloc( xdim, sizeof(void *) );
if( data == NULL )
return NULL;
for( x = 0; x < xdim; x++ )
data[x] = calloc( ydim, itemsize );
}
This allocates an array of pointers in which each item in the array is a pointer.
This is obviously C-style allocation. It can be converted to C++ style using new without too much effort.
|
|
|
|
|
Thanks a lot
|
|
|
|
|
Check out following link for safer ways to create a 2 dimensional dynamic array in C++.
http://www.tek-tips.com/faqs.cfm?fid=5575[^]
Top ten member of C++ Expert Exchange.
http://www.experts-exchange.com/Cplusplus
|
|
|
|
|
can someone please give me some ideas on how to draw a tic tac toe board using the C++ MFC App using a nested loop?
Thanks
|
|
|
|
|
|
can you give me an example on how to actually draw it?? im a beginner at this things right now.
Thanks
|
|
|
|
|
Software is an ever changing field. The most important skill you will develop is the ability to research.
http://msdn.microsoft.com[^]
Knock yourself out.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
i'm having trouble creating an add-in for ms word. some of the sample codes i received have errors in them. i want to create a command located under the Tools command bar. any ideas?????????
|
|
|
|
|
i face a similar problem. any suggestions anyone??
|
|
|
|
|
I am retriving a string from a SQL database. At the end of the string I need to add a hex 00 and a hex 04. No matter what I do I cannot seem to get the hex 00 and hex 04 tagged to the end.
I've tried do this with a byte array, a char array, CString.format. Nothing.
Here is my most recent code:
<br />
CString mySQLData = (char*)(_bstr_t)pRecordset->Fields->GetItem("MDC1_DATA_TEXT")->Value;<br />
<br />
char* myStringMsg = new char[strlen(mySQLData)];<br />
strcpy(myStringMsg, mySQLData);<br />
myStringMsg[strlen(mySQLData)] = 0x00;<br />
myStringMsg[strlen(mySQLData)+1] = 0x04;<br />
<br />
iSent = m_sConnectSocket.Send(myStringMsg, strlen(myStringMsg));<br />
Could someone please give me some insight into solving this problem.
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Two problems:
char* myStringMsg = new char[strlen(mySQLData)];
buffer allocated to small (use strlen(mySQLData)+2 )
Send(myStringMsg, strlen(myStringMsg));
strlen assumes myStringMsg is zero-terminated, therefore, the additional characters are mot sent.
use strlen(mySQLData)+2
(The second point holds true for strlen(mySQLData), the length returned "stops" at the first (char)0 encountered.
Pandoras Gift #44: Hope. The one that keeps you on suffering. boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
Nope. Still not passing the 0x00 and 0x04. Is there some other way to do it? In my older application I had a char 30000 large, and moved the string into it. But because it was a C-ISAM database that I was getting the string from, it did not strip out the 0x00 and 0x04 and I just passed the char value to the send function.
Since it seems as though SQLserver does strip the 0x00 and 0x04, I've got to try and put it in myself.
thanks for the help
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Could it be that the appendix is written (now), but isn't read from the database?
How is the column defined, and how do you read it?
Pandoras Gift #44: Hope. The one that keeps you on suffering. boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
the column is a text. I read it like this:
<br />
try<br />
{<br />
pCommand.CreateInstance(__uuidof(Command));<br />
pCommand->ActiveConnection = m_pConnection;<br />
pCommand->CommandText = _bstr_t("SELECT TOP 1 MDC1_DATA_TEXT FROM MDC1 WHERE (MDC1_I_O = 'O')");<br />
pRecordset.CreateInstance(__uuidof(Recordset));<br />
pRecordset->CursorLocation = adUseClient;<br />
pRecordset->Open((IDispatch*) pCommand, <br />
vtMissing,<br />
adOpenStatic,<br />
adLockBatchOptimistic,<br />
adCmdUnknown);<br />
_variant_t MDC1_DATA_TEXT;<br />
<br />
while (!pRecordset->adoEOF)<br />
{<br />
CString mySQLData = (char*)(_bstr_t)pRecordset->Fields->GetItem("MDC1_DATA_TEXT")->Value;<br />
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
|
forgot to mention that when I look at this field through enterprise manager it's missing the 0x00 and 0x04.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
HI all,
When creating an MFC (SDI / MDI). How do I get the app (EXE file) to display an icon of my choice in the directory area, instead of the annoying default IDR_MAINFRAME? Also, the with associated document, should I decided to serialise them.
Your guruship is most welcome.
Alton
|
|
|
|
|
Edit the two default icons presented in the Resources tab.
There should already be one for the EXE and another for the document.
If you want them to be different for some reason, then add additional icons to the resources and track down where they are loaded and assigned. Override those functions to return the icons of your choosing loaded from the resources.
|
|
|
|
|
Tried that, It works for the frame when app is up and running.
I've also rename say IDI_ICON1 to IDR_MAINFRAME and puts up a stubborn resistance.
Thanks, Blake anyway.
Alton
|
|
|
|
|
|
The easiest way to do this is to simply replace the two .ico files.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
How do you set a checkbox to checked on program startup?
IDC_CHECK SetCheck(IDC_CHECK) doesn't seem to work. Do I need a handle to the checkbox???
THX
|
|
|
|
|
Yes, or else use this:
HWND hWndControl = GetDlgItem(this->m_hWnd, IDC_CHECK);<br />
SendMessage(hWndControl, IDC_CHECK, BM_SETCHECK, wParam, BST_CHECKED, 0);
|
|
|
|