473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Set of Strings in Struct

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
  1. typedef struct Node {
  2.   char *name;
  3.   char **incoming;
  4.   char **new;
  5.   char **old;
  6.   char **next;  
  7. } Node;
  8.  
  9. Node *newNode(char *_inc, char *_new, char *_old, char *_next) {
  10.    Node *node = malloc(sizeof(Node));
  11.    node->name = "Node" + j++;
  12.    *(node->incoming) = _inc;   
  13.    *(node->new) = _new;
  14.    *(node->old) = _old;
  15.    *(node->next) = _next;
  16.    return(node);
  17. }
  18.  
  19. Node **expand(Node *_node, Node **_nodes_Set) {
  20.   int a = 0;
  21.  
  22.   if (_node->new == NULL) {
  23.     while (_nodes_Set[a] != NULL) {
  24.       if ((_nodes_Set[a]->old == _node->old) && (_nodes_Set[a]->next = _node->next)) {
  25.         *(_nodes_Set[a]->incoming + 1) = *_node->incoming;
  26.         return(_nodes_Set);
  27.       } else {
  28.         *(_nodes_Set + 1) = _node;
  29.         return(expand(newNode(_node->name, (char *)_node->next, NULL, NULL), _nodes_Set));
  30.       }      
  31.       a++;
  32.     }    
  33.   }  
  34. }
  35.  
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 2418
horace1
1,510 Expert 1GB
I think newNode() should be
Expand|Select|Wrap|Line Numbers
  1. Node *newNode(char *_inc, char *_new, char *_old, char *_next) {
  2.    Node *node = malloc(sizeof(Node));
  3.    node->name = "Node" + j++;
  4.    (node->incoming) = _inc;   
  5.    (node->new) = _new;
  6.    (node->old) = _old;
  7.    (node->next) = _next;
  8.    return(node);
  9. }
  10.  
and reason why you cannot use C++ and hence <set>
http://www.cppreference.com/cppset/index.html
Mar 7 '07 #2
I think newNode() should be
Expand|Select|Wrap|Line Numbers
  1. Node *newNode(char *_inc, char *_new, char *_old, char *_next) {
  2.    Node *node = malloc(sizeof(Node));
  3.    node->name = "Node" + j++;
  4.    (node->incoming) = _inc;   
  5.    (node->new) = _new;
  6.    (node->old) = _old;
  7.    (node->next) = _next;
  8.    return(node);
  9. }
  10.  
and reason why you cannot use C++ and hence <set>
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
horace1
1,510 Expert 1GB
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
  1. Node *newNode(char **_inc, char *_new, char *_old, char *_next) {
  2.    Node *node = malloc(sizeof(Node));
  3.    node->incoming = _inc;   
  4.    //*(node->new) = _new;
  5.    //*(node->old) = _old;
  6.    //*(node->next) = _next;
  7.    return(node);
  8. }
  9.  
  10. int main()
  11. {
  12.     char **inc={{"aaa"},{"bbbb"},{"cccc"}};
  13.     Node * node = newNode(inc, "bbb", "ccc", "ddd");
  14.  
Mar 7 '07 #4
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
horace1
1,510 Expert 1GB
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<string> and you add the char* strings to it as required?
Mar 7 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Noen | last post by:
def XOR(s1,s2): """ XOR string s1 with s2 """ output = "" # Argument check if (type(s1) and type(s2)) != type(""): raise TypeError, "Arguments are not strings" if len(s1) != len(s2): raise...
6
by: Stuart Norris | last post by:
Dear Readers, I am attempting to initialise a struct contiaing a dynamic character string. In the example below I am trying to initialise the name field so that my struct does not waste space. ...
4
by: John | last post by:
I'm trying (struggling) to use realloc to grow a list of strings. The number of strings is not known (this is a subset of an assignment to write a recursive ls program... my BS was in EE, so I'm...
13
by: jesper | last post by:
Hello, I have to load strings from a datbase and put them into an array. I get them by packets of 100 strings of 50 characters. Then I should do something like that : StringArray But x can be...
7
by: Mo | last post by:
I am having problem with marshaling struct in C#. //the original C++ struct typedef struct _tagHHP_DECODE_MSG { DWORD dwStructSize; // Size of decode structure. TCHAR ...
6
by: Jim Showalter | last post by:
I'm trying to write code that gets fixed-length strings from the user and then stores them in a linked list. Here's the definition of my list node: struct node {char str; struct node* next; };...
2
by: Tom Plunket | last post by:
I am building a file with the help of the struct module. I would like to be able to put Unicode strings into this file, but I'm not sure how to do it. The format I'm trying to write is...
1
by: Zach | last post by:
Greetings, I am writing a routine that will print out the beginning and end strings for a game: String A1 -"Begin msg1" String B1 -"End msg1" String A2 -"Begin msg2" String B2 -"End msg2"
28
by: hlubenow | last post by:
Hello, I really like Perl and Python for their flexible lists like @a (Perl) and a (Python), where you can easily store lots of strings or even a whole text-file. Now I'm not a...
19
by: bowlderyu | last post by:
Hello, all. If a struct contains a character strings, there are two methods to define the struct, one by character array, another by character pointer. E.g, //Program for struct includeing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.