This should be declared within the main function:
Code:
struct tstr_node *head;
This is not correct:
Code:
int sorted_list_insert(head , pstr_node);
You should include the parameter types in the function prototype, so it should have been:
Code:
int sorted_list_insert(struct tstr_node **head , struct tstr_node *pstr_node);
In the main function, this is not correct:
Code:
nod = sorted_list_insert(*head , pstr_node);
The reason is that head is a pointer to struct tstr_node, but the head parameter expects a pointer to a pointer to struct tstr_node. Therefore, you should write:
Code:
nod = sorted_list_insert(&head , pstr_node);
Looking at what you're trying to do in sorted_list_insert, I'd say that this is wrong:
Code:
struct tstr_node
{
char dataString[10][30];
struct tstr_node *next;
};
You probably want dataString to be, as the name say, a string rather than an array of strings. So it should have been:
Code:
struct tstr_node
{
char dataString[30];
struct tstr_node *next;
};
Speaking of which, I'd say that you should change sorted_list_insert to look like this:
Code:
int sorted_list_insert(struct tstr_node **head , const char *dataString)
The reason is that this insert function should focus on inserting the data as a node into the linked list. What you're doing right now is giving it two tasks:
- Read the data from the user.
- Insert the data as a node.
It is better to split each of these tasks into its own function. Furthermore, you aren't actually making use of the pstr_node parameter as a parameter: you're using it as an ordinary local variable.
Oh, and one more thing: do not use gets as it is inherently vulnerable to buffer overflow. Try fgets as an alternative, though remember that fgets stores the trailing newline from reading the line into the string if there is space for it.