0

I have a simple question about this code

struct a
{
    char key;
    a *next;
};
a = here*;

and in the function I check if here is NULL or not

if (here->key==NULL)
...

and Im sure here is pointing to an a(struct) but it gives access violation . what should I do to check if something Is NULL or not ?

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by deceptikon
1

a = here*;

This isn't valid syntax.

and in the function I check if here is NULL or not

You're not checking if here is NULL, you're checking if here->key is NULL. here->key is a char, so the test is nonsensical given that one of the operands is not a pointer. If here is NULL then trying to access key will result in an access violation. You want to do this:

if (here == NULL)

Edited by deceptikon

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.