446,227 Members | 1,373 Online
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

Set of Strings in Struct

 P: 5 Right, I have to, for a assignment write a translator that translates Linear Temporal Logic formulae into Buchi automata in C. Now part of what I have at the moment is: Expand|Select|Wrap|Line Numbers typedef struct Node {   char *name;   char **incoming;   char **new;   char **old;   char **next;   } Node;   Node *newNode(char *_inc, char *_new, char *_old, char *_next) {    Node *node = malloc(sizeof(Node));    node->name = "Node" + j++;    *(node->incoming) = _inc;       *(node->new) = _new;    *(node->old) = _old;    *(node->next) = _next;    return(node); }   Node **expand(Node *_node, Node **_nodes_Set) {   int a = 0;     if (_node->new == NULL) {     while (_nodes_Set[a] != NULL) {       if ((_nodes_Set[a]->old == _node->old) && (_nodes_Set[a]->next = _node->next)) {         *(_nodes_Set[a]->incoming + 1) = *_node->incoming;         return(_nodes_Set);       } else {         *(_nodes_Set + 1) = _node;         return(expand(newNode(_node->name, (char *)_node->next, NULL, NULL), _nodes_Set));       }             a++;     }       }   }   Node->incoming; new; old and next must all be sets of strings. And I must be able to add to them. _node_Set must be an array of Nodes to which I can add. My problem is, as it is here it compiles, but when I run it it throws a SIGSEGV when it gets to *(node->incoming) = _inc; in newNode(); As you can see I have no clue how to program in this language, my experience is with C++ and I'm missing many of its build-in features. Please help. Mar 7 '07 #1
5 Replies

 Expert 100+ P: 1,510 I think newNode() should be Expand|Select|Wrap|Line Numbers Node *newNode(char *_inc, char *_new, char *_old, char *_next) {    Node *node = malloc(sizeof(Node));    node->name = "Node" + j++;    (node->incoming) = _inc;       (node->new) = _new;    (node->old) = _old;    (node->next) = _next;    return(node); }   and reason why you cannot use C++ and hence http://www.cppreference.com/cppset/index.html Mar 7 '07 #2

 P: 5 I think newNode() should be Expand|Select|Wrap|Line Numbers Node *newNode(char *_inc, char *_new, char *_old, char *_next) {    Node *node = malloc(sizeof(Node));    node->name = "Node" + j++;    (node->incoming) = _inc;       (node->new) = _new;    (node->old) = _old;    (node->next) = _next;    return(node); }   and reason why you cannot use C++ and hence http://www.cppreference.com/cppset/index.html Hmmm no that won't work (and it doesn't I tried) char **increment is supposed to be an array of strings. Node->increment = _inc (as far as I understand) if you cast to get the types right will simply force Node->increment to become an array of chars. Edit: Typo Mar 7 '07 #3

 Expert 100+ P: 1,510 Hmmm no that won't work (and it doesn't I tried) char **increment is supposed to be an array of strings. Node->increment = _inc (as far as I understand) if you cast to get the types right will simply force Node->increment to become an array of chars. Edit: Typo in that case should the _inc paramater be char **, e.g. (ignore the other parameters for now) Expand|Select|Wrap|Line Numbers Node *newNode(char **_inc, char *_new, char *_old, char *_next) {    Node *node = malloc(sizeof(Node));    node->incoming = _inc;       //*(node->new) = _new;    //*(node->old) = _old;    //*(node->next) = _next;    return(node); }   int main() {     char **inc={{"aaa"},{"bbbb"},{"cccc"}};     Node * node = newNode(inc, "bbb", "ccc", "ddd");   Mar 7 '07 #4

 P: 5 Hm okay right but with newNode(_inc, _new, _old, _next) or whatever, _inc represents the first string in the array or set or whatever. Later in expand I have to be able to add more string to it, sometimes append an array of strings to the end of it. That is why I'm using the double pointers. Is there anyway to do what I want, because with your above solution once the node is create the array is pretty much set. Mar 7 '07 #5

 Expert 100+ P: 1,510 Hm okay right but with newNode(_inc, _new, _old, _next) or whatever, _inc represents the first string in the array or set or whatever. Later in expand I have to be able to add more string to it, sometimes append an array of strings to the end of it. That is why I'm using the double pointers. Is there anyway to do what I want, because with your above solution once the node is create the array is pretty much set. if you are working in C++ could node->incoming be a vector and you add the char* strings to it as required? Mar 7 '07 #6