muser wrote:[color=blue]
> 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[i] 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];[/color]
All right, you have an array of four pointers to char, each of which
is of indeterminate value.
[color=blue]
> char* BAN;[/color]
Now you have another pointer to char, also of indeterminate value.
[color=blue]
>
> strncpy(AN[4], &record[27], 4);[/color]
Now you're trying call `strncpy()' using as a destination a value
that doesn't even exist! (in `char* AN[4]' valid indices range from
0 to 3).
You've invoked undefined behavior -- so *anything* can happen.
[color=blue]
> AN[4] = '\0';
>
>
> for(int i=0; i < 4; i++)
>
> if(AN[i] = " ") // check that last character is a number and the
> next character[/color]
Erm, no. You're *assigning* the address of the string literal
'" "' to AN[i]. All well and good (unlike the above), but
certainly not what you intended to do. Besides, this test *cannot fail*.
[color=blue]
> {
> //is a char.
> BAN = (AN[i] + 1 ) ;
> if(!isalpha(BAN[i])){}
>
> }
> return false;
>
> if(AN[i] = " ") // check that last character is a number and the
> next character[/color]
See above. You're doing the same thing.
[color=blue]
> {
> //is a char.
> BAN = (AN[i] - 1);
> if(!isdigit(BAN[i])){};
>
> }
> return false;
>
>
> if(AN[i] = ";")
> {
>
> BAN = (AN[i] - 1);
>
> if(!isdigit(BAN[i])){};
> }
> return false;
>
> if(AN[i] = ";")
> {
> BAN = (AN[i] + 1);
>
> if(!isalpha(BAN[i])){};
>
> }
> return false;
>
> if(AN[i] = ";")
> {
> BAN = (AN[i] + 1);
>
> for(int i=0; i < 17; i++)
> if(!isalpha(BAN[i]))
> return false;
> }
>
> return true;
>
> }[/color]
I'd be surprised if there aren't even more errors here.
Rethink what you're doing, get a good C book (see
http://www.accu.org for suggestions) and post back if you run into
problems.
Unfortunately, you've got a ways to go.
HTH,
--ag
--
Artie Gold -- Austin, Texas