Stack smashing detected (Aborted Core Dump)

My codes is suppose to replicate the strncat() function. The codes give the desired output, but it always ends up with the stack smashing detected error. I’d like to know why and how to fix it. What am I doing wrongly or not doing at all? main.h #ifndef MAIN_H #define MAIN_H #include <stdio.h> #include <string.h>… Read More Stack smashing detected (Aborted Core Dump)

When I run my code it display random symbols at the end

I am separating a string into words and when I run the source code, it works but at the end it displays random symbols and letter. #include <iostream> #include <cstring> #include <cctype> using namespace std; void seperatestring(string str); int main() { string str; cout << "Enter a string: "; getline(cin, str); seperatestring(str); return 0; }… Read More When I run my code it display random symbols at the end

This simple C code about string arrays works while it shoudn't and I don't know why

I know there are other ways to solve this like with a calloc but the question here is why does it work while it shouldn’t? #include <stdio.h> #include <stdlib.h> #include <string.h> void function (char **, char **); int main () { char *list[2], *list1[] = {"word0", "word1", "word2"}; function(list, list1); return 0; } void function… Read More This simple C code about string arrays works while it shoudn't and I don't know why

Same output when printing out a tree in C11

struct Node{ char *key; struct Node *sx, *dx; }; typedef struct Node Node; int main(void){ Node *root = NULL; //node->dx = newNode(3); char *str = malloc(sizeof(char)*5); if(scanf("%s", str) == 1) root = insert(root, str); while(strcmp(str, "#end") != 0){ if(scanf("%s", str) == 1) if(strcmp(str, "#end") != 0) insert(root, str); else break; else printf("error\n"); } printTree(root); }… Read More Same output when printing out a tree in C11