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: -
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.
5 2418
I think newNode() should be -
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 <set> http://www.cppreference.com/cppset/index.html
I think newNode() should be -
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 <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
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) -
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");
-
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.
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?
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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. ...
|
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...
|
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...
|
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 ...
|
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; };...
|
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...
|
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"
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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,...
| |