Re: Undeclared identifier???
"Acken" <erictham115@gmail.com> wrote in message
news:1135557667.261341.211750@g43g2000cwa.googlegr oups.com[color=blue]
> 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!!![/color]
currentVal is out of scope.
[color=blue]
> "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};[/color]
// missing closing " above;
// you never define i and j below.[color=blue]
>
> for (i = 0; i < 1; ++i)
> for (j = 0; j < 3; ++j)
> BYTE currentVal =
> (BYTE)strlen(g_rgStaticWorksheetFuncs[i][j]); //ok[/color]
The operation of the for() loops ends here, as does the scope of anything
declared within them.
[color=blue]
> g_rgWorksheetFuncs[i][j] = new char[currentVal +2]; //??[/color]
// why +2 instead of +1?
[color=blue]
> memset(g_rgWorksheetFuncs[i][j], '\0', currentVal +2 ); //??
> memcpy(g_rgWorksheetFuncs[i][j],[/color]
// why not just use strcpy?
[color=blue]
> g_rgStaticWorksheetFuncs[i][j],currentVal); //??
> g_rgWorksheetFuncs[i][j]= currentVal; //??[/color]
// 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 |