By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,590 Members | 635 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,590 IT Pros & Developers. It's quick & easy.

Please help me while dereferencing a pointer array

P: 56
Hi,
I am having the following block of code. Should I use a NULL checking for tokens[i], where ever there is *tokens[i]. Please let me know soon.

while( !infile.eof() )
{
DmgString lineStr;

char str[500];
infile.getline (str, 499 );
lineStr = str;

if( lineStr.IsBlank() == dmgYES )
{
continue;
}
else
{
lineStr.NoSpaces();
lineStr.ToUpper();

DmgPtrList<DmgString> tokens;
lineStr.Tok(',',tokens);

if ( tokens[0] != NULL )
{
int i = 0;

if ( strcmp( (const char*)*tokens[i],
(const char*) "TRADETYPE" ) == 0 )
{
for ( i = 1; i<tokens.entries(); i++ )
{
tradeTypeList.insert( new DmgString ( *tokens[i] ) );
}
}
else if ( strcmp(
(const char*)*tokens[i], "DOCFUNCTION" ) == 0 )
{
for ( i = 1; i<tokens.entries(); i++ )
{
docFunctionList.insert( new DmgString ( *tokens[i] ) );
}
}
}
}
}



Thanks in advance.
Aug 6 '07 #1
Share this Question
Share on Google+
3 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
Please re-post using code tags and proper indentation.

It's hard to read your code.
Aug 6 '07 #2

P: 56
Here I am posting with proper indentation but I dont know what is code tag.

while( !infile.eof() )
{
DmgString lineStr;

char str[500];
infile.getline (str, 499 );
lineStr = str;

if( lineStr.IsBlank() == dmgYES )
{
continue;
}
else
{
lineStr.NoSpaces();
lineStr.ToUpper();

DmgPtrList<DmgString> tokens;
lineStr.Tok(',',tokens);

if ( tokens[0] != NULL )
{
int i = 0;

if ( strcmp( (const char*)*tokens[i],
(const char*) "TRADETYPE" ) == 0 )
{
for ( i = 1; i<tokens.entries(); i++ )
{
tradeTypeList.insert( new DmgString ( *tokens[i] ) );
}
}
else if ( strcmp(
(const char*)*tokens[i], "DOCFUNCTION" ) == 0 )
{
for ( i = 1; i<tokens.entries(); i++ )
{
docFunctionList.insert( new DmgString ( *tokens[i] ) );
}
}
}
}
}
Aug 7 '07 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
docFunctionList.insert( new DmgString ( *tokens[i] ) );
}
}
}
}
}
is not indented.

The code tags are shown iun the Reply Guildlines that's just to the right of the posting window. You are probably losing the indentation due to no code tags.

[ code = cpp ]

code goes here

[ /code ]

The actual code tags are like the ones above without the embedded spaces.
Aug 7 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.