I suggest using a different language than C. C is ancient and primitive and does not work the way you're conceiving of it. Notably, your function signature is unworkable because arrays are not first class entities in C, and so that signature is exactly equivalent to
BST *newNode(int ID, char* name, char* surname, int* friendsID) ...
As you can see, these are simply pointers to the data; they have no length associated with them. Whenever passing arrays to functions in C, you must always pass the length of the array as well, unless there's some other way to determine the length -- e.g., being NUL-terminated, as the convention for C "strings" (in scare quotes because there is no string datatype in C).
Note that the arrays in BST have fixed size lengths, so you are begging for array overruns. It would be better to declare these as pointers (note other improvements in the declaration syntax):
typedef struct BST BST;
struct BST
{
int ID;
char* name;
char* surname;
int* friendsID;
BST* left;
BST* right;
};
Then you could have (note various improvements and corrections)
BST *newBST(int ID, char* name, char* surname, int* friendsID)
{
BST* bst = malloc(sizeof *bst);
if (!bst)
{
fprintf(stderr, "Out of memory.\n");
exit(1);
}
bst->ID = ID;
bst->name = name;
bst->surname = surname;
bst->friendsID = friendsID;
bst->left = bst->right = NULL;
return bst;
}
provided that the name
, surname
, and friendsID
arguments were all malloced and that friendsID
is terminated with a sentinel value or that you have some other way to know its length. Otherwise, you need to pass the number of friends as an argument to newBST and store it in your BST node.