I have a strange problem that is driving me nuts (easily done).
I have a function that is passed a pointer to char. I then
parse the string pointed to by the pointer. I check the
characters and decide if I want to stop.
Anyway, the first way I tried to do this always produced an
error so I came up with a different way. The second way
never produces an error.
I'm wondering if someone can tell me the difference and why one
causes a run-time error and one does not? The pointer (ptr) is
initialized and points to a valid number. The character tested
may be NULL, if end of string is reached. The first 'if' statement
always generates an error and the 2nd does not. Why?
int TestFunction(char * ptr)
{
char tmpChar;
tmpChar = *ptr; // *ptr may be NULL
// always generates run-time
if(tmpChar != ':' && tmpChar != ';') { // some code }
// never generates run-time error
if(*ptr != ':' && *ptr != ';') { // some code }
// additional code not shown
What is the technical difference that might cause one to generate
a run-time error and one does not?
--
-----------------------------------------------------------------
Discussion Group: http://www.halcyon.com/ipscone/wwwboard/
Protect your constitutional rights. Your favorite one may be next!
-----------------------------------------------------------------