2 Structs Defined Follows Struct Token Int Tokenid Char Tokenname Char Tokenword Token Str Q37138885

I have 2 structs defined as follows:

struct token
{
   int tokenID;
   char *tokenName;
   char *tokenWord;

}token;

and

struct node
{
   char nodeName[8]; // no token name longer than 8characters.
   struct token *token1;
   struct token *token2;
   struct token *token3;
   struct node *child1;
   struct node *child2;
   struct node *child3;
   struct node *child4;
};

notice struct node contains pointer to struct tokens. How wouldI access the token name from a token in node. When I try:

node->token1->tokenName I get a segmentation fault.


Answer


#include<iostream>using namespace std;struct token{ int tokenID; char *tokenName; char *tokenWord;}token;struct node{ char nodeName[8]; // no token name longer than 8

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.