Every time I attempt to insert a string into a binary tree in my program, I have to use strcpy
and use the strcpy
's destination for it to insert successfully. If I do not use strcpy
and use just the source, it will crash the program.
Example:
char *originalstring;
originalstring = (char *)calloc(alloc + 1, sizeof(char));
originalstring = "Hello.";
insert(&root, originalstring); //into binary tree
Results in a crash.
char *newstring, *originalstring;
originalstring = (char *)calloc(alloc + 1, sizeof(char));
originalstring = "Hello.";
newstring = (char *)calloc(alloc + 1, sizeof(char));
strcpy(newstring, originalstring);
insert(&root, newstring);
Inserts it into the tree. My full program is of course significantly larger than this, but I really don't think it has anything to do with me being forced to use a strcpy
to insert a string. This leads me to asking whether or not strcpy
has special things.
Edit: I have also attempted to manually nullbyte the end of originalstring
and that has failed.