|
AnShUmAn wrote: int *p[10];
it is a two dimensional array and its elements can be accessed as
p[0][0],p[0][1].....
i think int *p[10] is array of 10 pointers.. am i right?
where we have to allocate the memory for each..
Knock out 't' from can't,
You can if you think you can
-- modified at 2:27 Wednesday 7th June, 2006
|
|
|
|
|
See for int *p[10];
<br />
int *p[2];<br />
memset(&p,0,sizeof(int[2]));<br />
<br />
int b=10;<br />
p[0]=&b;<br />
int c;<br />
c=20;<br />
p[1]=&c;<br />
<br />
int A;<br />
A=*p[0];<br />
A=*p[1];<br />
whitesky
|
|
|
|
|
int *p[10]
is a array of 10 pointers.
and i think second one is pointer to an array of 10 integers.
or you may declare it as int **p
assign memory to *p of 10 blocks so it will be an array
and then **p will be the pointer to array of 10 integers.
Leya
|
|
|
|
|
Since in operator precedence the "[] " operator has a priority above the "* " operator, the expression "int *p[10] " denotes an array of ten pointers, each pointing to an integer. In "int (*p)[10] " the order of interpretation was changed, and here we have a pointer to an array of ten integers.
In the first case, the size of p is 40 bytes (in our compiler), in the second case, the size is 4 bytes.
In the first case, you can assign new value for each array element like this:
p[2] = &z;
p[7] = new int;
Expression like *p[2] here can be used to change the value of z :
*p[2] = 100;
In the second case, you first have to allocate an array and assign its address to the pointer:
p = (int (*)[10]) new int [10];
Now you can access elements from this array:
(*p)[3] = 100;
(*p)[5] = 200;
Then you can delete the array:
delete [] p;
|
|
|
|
|
Viorel wrote: p = (int (*)[10]) new int [10];
Is it necessary to typecast the allocated memory ??
As per my knowledge the new operator returns the appropriate pointer.
or Should we allocate memory as
p = new int [5][10];
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
I think, with older compilers an assignment like "int (*p)[10] = new int [10] " would work, but today, in VS 2003 or GCC, it is not acceptable. Compiler complains: "cannot convert from 'int *' to 'int (*)[10]'". I suppose this is made to follow standards.
Regarding the second question, yes, you can make the assignment "int (*p)[10] = new int [5][10] " if you are going to interpret p as a pointer to bi-dimensional array. You can refer the elements like p[2][7] .
|
|
|
|
|
Viorel wrote: int (*p)[10] = new int [10]
fine..
int (*p)[10] =(int (*)[10]) new int [10]; How many elements array able to hold.
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
As I know the number of array’s elements, as well as the number of dimensions in multi-dimensional array is not limited by the language, but is limited by the compiler, libraries and available resources.
The size of available memory is a factor which determines the array’s limits. If no enough memory for new operator, an exception is thrown.
Compiler and libraries included in VS 2003 enforce the total size of an array to be less then 0xFFFFFFFF. Therefore an array of integers cannot have more then approx. 1e9 elements, but the available memory space is usually smaller.
|
|
|
|
|
RahulRKulkarni wrote: I want to build an application of login and call google user.
I am going to use libjingle application.
any suggetions, ideas needed.
Search for google API's and through them validate the Google user.
following link have sample requests for validating the client login..
Here[^]
Hope this helps you.
Knock out 't' from can't,
You can if you think you can
-- modified at 2:08 Wednesday 7th June, 2006
|
|
|
|
|
Link give page not found error
Rahul Kulkarni
|
|
|
|
|
RahulRKulkarni wrote: Link give page not found error
Check it again... sorry some text missed in link
welcome to CP
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
Found
Thanks.
Let's see how it helps to me
Rahul Kulkarni
|
|
|
|
|
Hi ,
I have to display 2 sheet in single Excel application. I am using CWorkbook,CWorkbooks,CWorksheet,CWorksheets class for it. But I am not able to display it.Can any one know how to do this using this classes.
Mike
|
|
|
|
|
Hi ,
By Default it should have added default no of sheets in your excel according to the setting in the excel in mine its three .
You can also customize it using the following code :-
int lNoOfSheetsInNewWorkBook =2;
books = app.GetWorkbooks();
app.SetSheetsInNewWorkbook(lNoOfSheetsInNewWorkBook);
book = books.Add (covOptional);
Regards,
FarPointer
Blog:http://farpointer.blogspot.com/
|
|
|
|
|
Hi,
Thanks. I know the way u suggest. But is their any other way to do this because I have delete third sheet in this case or I may require to add the chart instead of sheet(i.e 1 sheet,1 chart in Excel). That's why I am looking for adding sheet/chart separetly.
|
|
|
|
|
Hi ,
You mean like this :-
_Worksheet objWorkSheet;
LPDISPATCH lpDipatch;
VARIANT sheetVar = {(short)(2 + nNewSheet)};
int count = sheets.GetCount();
objWorkSheet = sheets.GetItem(COleVariant( (short)(2 + nNewSheet)));
// Create References
sheetVar.vt = VT_DISPATCH;
sheetVar.pdispVal = objWorkSheet.m_lpDispatch;
objWorkSheet.m_lpDispatch->AddRef();
// Add new sheet at the end
lpDipatch = sheets.Add( covOptional, sheetVar,
covOptional, covOptional);
VariantClear(&sheetVar);
objWorkSheet.AttachDispatch( lpDipatch );
objWorkSheet.ReleaseDispatch();
objWorkSheet.DetachDispatch();
Regards,
FarPointer
Blog:http://farpointer.blogspot.com/
|
|
|
|
|
Hi,
I am doing like this.
CWorkbooks m_books=m_app.get_Workbooks();
m_books=m_books.Add(COleVariant(xlWorkSheet));
Like this way I am able to create 1 sheet. If I add 2nd sheet using this way then 2nd sheet open in another Excel application.
|
|
|
|
|
Hello c++ friends!
I am currently working on a handy program that scans temperature/fan control for boat engines. However I am stuck at the moment, I want it to write the average values (average value, maximum values and minimum values) to a text file hourly/daily or whatever time i define. Below is some code..
This one works just fine, it writes current temperature to a text file once every second:
void CAnalogTag::StoreData (double dRawData, BOOL bLive)
{
double dValue;
EnterCriticalSection(&m_csAccess);
m_dPrevRawValue = m_dLatestRawValue;
m_dLatestRawValue = dRawData;
LeaveCriticalSection(&m_csAccess);
if (m_pSecondsBin && bLive)
m_pSecondsBin->StoreDataPoint(dRawData);
std::ofstream ScanFile ("scanfile.txt", std::ios_base::app);
ScanFile << "Temperature: " << dRawData << endl << "Offset: " << m_dOffset << "\n";
ScanFile.close();
}
""
That works just fine, I think below is where the values that i want are stored, but I don't know how or if it's even possible to extract them:
""
void CAnalogTag::StoreData(void *pData, void *pMinData, void *pMaxData, long nNumPts, int nTrendType)
{
CArray<double, double&=""> *pTrendData = (CArray<double,double&> *)pData;
CArray<double, double&=""> *pMinTrendData = (CArray<double,double&> *)pMinData;
CArray<double, double&=""> *pMaxTrendData = (CArray<double,double&> *)pMaxData;
// store an entire array of data to the bin
switch (nTrendType)
{
case trend_seconds:
if (m_pSecondsBin)
m_pSecondsBin->SetEntireTrend(pTrendData, pMinTrendData, pMaxTrendData, nNumPts);
break;
case trend_minutes:
if (m_pMinutesBin)
m_pMinutesBin->SetEntireTrend(pTrendData, pMinTrendData, pMaxTrendData, nNumPts);
break;
case trend_hours:
if (m_pHoursBin)
m_pHoursBin->SetEntireTrend(pTrendData, pMinTrendData, pMaxTrendData, nNumPts);
break;
case trend_days:
if (m_pDaysBin)
m_pDaysBin->SetEntireTrend(pTrendData, pMinTrendData, pMaxTrendData, nNumPts);
break;
}
}
""
Any help would be appreciated.. Been stuck here for the last few days, and i think my boss is losing his patience
Cheers,
Nalle
|
|
|
|
|
i'm a layman for VC++, can anyone be kind to recommend me a book for accidence.thanks a lot
|
|
|
|
|
Microsoft Press books can be preferred.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
thank you
|
|
|
|
|
Do you want to learning VC
whitesky
|
|
|
|
|
I used IHTMLBodyElement to set the background picture,but I can't set the repeat property,and background-position-x,background-position-y.
What can I do?
|
|
|
|
|
I have solved the problem.
;)
|
|
|
|
|
I'm trying to learn C++, so I'm just building some sample classes to get some experience. I have a matrix class in which I have implemented an addition operator that looks like this...
matrix operator + (matrix& toAdd)
{
// Create a zero matrix to output.
matrix output = matrix(toAdd.get_rows(), toAdd.get_cols(), 0);
// A temporary variable for the sum of each element
double val;
// Go through every element and add them together
// Stick the result in the output matrix
for(int i = 0; i < nrows; i++)
{
for(int j = 0; j < ncols; j++)
{
// The array indices are always 1 less
// than the row or column number
val = elements[i][j] + toAdd.get_el(i+1,j+1);
output.set_el(i+1, j+1, val);
}
}
return output;
}
It's nothing fancy... hopefully you won't need to see the whole class to understand the problem.
I wanted to pass it a matrix by reference in case the matrix is huge. I figure it'd probably be good form to add a const so that it is
matrix operator + (const matrix& toAdd)
but if I add that in, it doesn't compile. I get errors like
"passing 'const matrix' as 'this' argument of 'int matrix::get_rows()' discards qualifiers"
I get one of those errors for every time I use a member function of toAdd. Without const, everything's fine, but the matrix referred to as toAdd is vulnerable to changes. I am using gcc (or, more accurately, g++) to compile. Let me know if you need more information. Thanks!
-Mark
|
|
|
|
|