struct & union difficulty. getting segmentation fault error.
I am getting segmentation fault error while debugging. while running normally, nothing is displayed including no error.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <iostream>
#include <cstring>
using namespace std;
union u1
{
struct trinode* arrayptr[26];
char* chararrayptr;
};
typedef
struct trinode
{
int tag;
union u1 option;
char* asitis;
}* trptr;
int main()
{
char word[20];
trinode* root;
root->tag=1;
for(int i=0;i<26;i++)
root->option.arrayptr[i]=NULL;
root->asitis=NULL;
cout<<"Enter the word: ";
cin>>word;
}
|
You are accessing an uninitialized pointer variable. Of course this is what we call "access violation".
1 2
|
trinode* root; // Not initialized
root->tag = 1; // The problem
|
Topic archived. No new replies allowed.