473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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; //??

Dec 26 '05 #1
1 4011
"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


Dec 26 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Saurabh Aggrawal | last post by:
Hi, if (iter->m_name.compare(pstrName) == 0) { // Provide our object. *ppunkItem = iter->m_pUnknown; // Addref our object... iter->m_pUnknown->AddRef(); break; }
9
by: W. Van Hooste | last post by:
Just starting with C, can somebody explain why this does not work or point me in the right direction? I wrote some tools and did some coding but cant seem to get this one. I DID declare my FILE...
5
by: Marc Gustafson | last post by:
This function is executed when a application file is double-clicked to open in a VC++ application. Specifically, this function is enabled by RegisterShellFileTypes () in the application's...
0
by: Stephanie Doherty | last post by:
Hello World, I am trying to use a _spawnl function like this (and I have included the process.h file): _spawnl(_P_WAIT,iporgfile,iporgfile,NULL); It compiles with the following errors: ...
6
by: Peter Rothenbuecher | last post by:
Hello, when I try to compile the following code with g++ -o client client.c #include<sys/socket.h> #include<stdio.h> #include<stdlib.h> #define ADDRESS "mysocket"; #define MAXLEN 200;
10
by: teddarr | last post by:
I am trying to construct a class with several functions and identifiers. The identifier in question is static double AIR which will hold the value of the annual interest rate in the class. I have...
2
by: aarthi28 | last post by:
Hi, I have this code that I am trying to compile, but I am getting the following errors 'CoInitializeSecurity': identifier not found 'EOAC_NONE' : undeclared identifier I have pasted the...
5
by: vmagana | last post by:
First of all I would like to indicate that I am a newbie a programming. I am having a problem compiling a sample source code that I downloaded from microsoft. When I try to build the program I get...
3
by: Anna Smidt | last post by:
Thanks for the help so far. I have some problems left. One of them is an undeclared identifier, but it's unclear to me why the compiler fights with me. It says "iter: undeclared identifier" I...
1
by: LuxCkrown | last post by:
Hey everyone, i've been browsing for a fix to my problem 1>c:\documents and settings\user\desktop\judis_repack\judis repack\judis repack\maplestoryserver\inventory.cpp(386) : error C2065: 'amount'...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.