M
muser
I'm writing a function that isn't showing as an error during
compilation, but it is at run time. The exception it is throwing
informs me that it is due to my two pointers in that function. It is
an access violation error, where the memory can't be read. I'll list
the things I've tried in order to resolve the problem so that no one
will suggest the same thing. I've tried initialising AN[4] as a just a
character pointer, then just as a character variable, neither works as
the rest of the function requires it to be both a pointer array
variable. I've tried referencing BAN =& AN[4], which neither worked
and rightly so as the function checks to see whether AN is isalpha
or a space, if encountered the next element in the array requires
checking, and the one preceeding it. BAN is used to get either the
preceeding element or the one following it.
Thank you in advance for your help in this matter.
bool CheckAddressN( char* record )
{
char* AN[4];
char* BAN;
strncpy(AN[4], &record[27], 4);
AN[4] = '\0';
for(int i=0; i < 4; i++)
if(AN = " ") // check that last character is a number and the
next character
{
//is a char.
BAN = (AN + 1 ) ;
if(!isalpha(BAN)){}
}
return false;
if(AN = " ") // check that last character is a number and the
next character
{
//is a char.
BAN = (AN - 1);
if(!isdigit(BAN)){};
}
return false;
if(AN = ";")
{
BAN = (AN - 1);
if(!isdigit(BAN)){};
}
return false;
if(AN = ";")
{
BAN = (AN + 1);
if(!isalpha(BAN)){};
}
return false;
if(AN = ";")
{
BAN = (AN + 1);
for(int i=0; i < 17; i++)
if(!isalpha(BAN))
return false;
}
return true;
}
compilation, but it is at run time. The exception it is throwing
informs me that it is due to my two pointers in that function. It is
an access violation error, where the memory can't be read. I'll list
the things I've tried in order to resolve the problem so that no one
will suggest the same thing. I've tried initialising AN[4] as a just a
character pointer, then just as a character variable, neither works as
the rest of the function requires it to be both a pointer array
variable. I've tried referencing BAN =& AN[4], which neither worked
and rightly so as the function checks to see whether AN is isalpha
or a space, if encountered the next element in the array requires
checking, and the one preceeding it. BAN is used to get either the
preceeding element or the one following it.
Thank you in advance for your help in this matter.
bool CheckAddressN( char* record )
{
char* AN[4];
char* BAN;
strncpy(AN[4], &record[27], 4);
AN[4] = '\0';
for(int i=0; i < 4; i++)
if(AN = " ") // check that last character is a number and the
next character
{
//is a char.
BAN = (AN + 1 ) ;
if(!isalpha(BAN)){}
}
return false;
if(AN = " ") // check that last character is a number and the
next character
{
//is a char.
BAN = (AN - 1);
if(!isdigit(BAN)){};
}
return false;
if(AN = ";")
{
BAN = (AN - 1);
if(!isdigit(BAN)){};
}
return false;
if(AN = ";")
{
BAN = (AN + 1);
if(!isalpha(BAN)){};
}
return false;
if(AN = ";")
{
BAN = (AN + 1);
for(int i=0; i < 17; i++)
if(!isalpha(BAN))
return false;
}
return true;
}