"Acken" <er*********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com
Hi i have spent almost 2 days on these now..and cannot figure out what
is wrong?! It seems so simple and innocent , but it is stumbling a
novice of me. Please help to point out anything wrong and many thanks
in advance!!!
currentVal is out of scope.
"currentVal" below is identified as undeclared identifier in lines
//??. I thought it was already defined as BYTE (which was typedef
unsigned char) in another header file.
static char* g_rgWorksheetFuncs[1][3];
static char* g_rgStaticWorksheetFuncs[1][3] =
{" ewma", " BRR"," EWMA};
// missing closing " above;
// you never define i and j below.
for (i = 0; i < 1; ++i)
for (j = 0; j < 3; ++j)
BYTE currentVal =
(BYTE)strlen(g_rgStaticWorksheetFuncs[i][j]); //ok
The operation of the for() loops ends here, as does the scope of anything
declared within them.
g_rgWorksheetFuncs[i][j] = new char[currentVal +2]; //??
// why +2 instead of +1?
memset(g_rgWorksheetFuncs[i][j], '\0', currentVal +2 ); //??
memcpy(g_rgWorksheetFuncs[i][j],
// why not just use strcpy?
g_rgStaticWorksheetFuncs[i][j],currentVal); //??
g_rgWorksheetFuncs[i][j]= currentVal; //??
// why are you assigning an unsigned char to a pointer to char?
Try this:
static char* g_rgWorksheetFuncs[1][3];
static char* g_rgStaticWorksheetFuncs[1][3] ={" ewma", " BRR"," EWMA"};
int main()
{
for (int i = 0; i < 1; ++i)
{
for (int j = 0; j < 3; ++j)
{
BYTE currentVal =
(BYTE)strlen(g_rgStaticWorksheetFuncs[i][j]);
g_rgWorksheetFuncs[i][j] = new char[currentVal +1];
memset(g_rgWorksheetFuncs[i][j], '\0', currentVal +1 );
memcpy(g_rgWorksheetFuncs[i][j],
g_rgStaticWorksheetFuncs[i][j],currentVal);
}
}
return 0;
}
or, better still:
static char* g_rgWorksheetFuncs[1][3];
static char* g_rgStaticWorksheetFuncs[1][3] ={" ewma", " BRR"," EWMA"};
int main()
{
for (int i = 0; i < 1; ++i)
{
for (int j = 0; j < 3; ++j)
{
BYTE currentVal =
(BYTE)strlen(g_rgStaticWorksheetFuncs[i][j]);
g_rgWorksheetFuncs[i][j] = new char[currentVal +1];
strcpy(g_rgWorksheetFuncs[i][j],
g_rgStaticWorksheetFuncs[i][j]);
}
}
return 0;
}
Even better (for most purposes) would be to use std::string rather than
char* strings.
--
John Carson