Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 26th, 2005, 12:55 AM
Acken
Guest
 
Posts: n/a
Default Undeclared identifier???

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" 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};

for (i = 0; i < 1; ++i)
for (j = 0; j < 3; ++j)
BYTE currentVal =
(BYTE)strlen(g_rgStaticWorksheetFuncs[i][j]); //ok
g_rgWorksheetFuncs[i][j] = new char[currentVal +2]; //??
memset(g_rgWorksheetFuncs[i][j], '\0', currentVal +2 ); //??
memcpy(g_rgWorksheetFuncs[i][j],
g_rgStaticWorksheetFuncs[i][j],currentVal); //??
g_rgWorksheetFuncs[i][j]= currentVal; //??

  #2  
Old December 26th, 2005, 01:25 AM
John Carson
Guest
 
Posts: n/a
Default 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




 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles