C programming Linked List
Hi,
I am new in learning linked list.
I try to make a program using a function
int sorted_list_insert(struct tstr_node **head , struct tstr_node *pstr_node) with a double pointer to the head.
It is important for me to keep the prototype as it is well. Function return 1 in case of succes and o otherwise. Thank you.
Code:
#include <stdio.h>#include <string.h>
#include <stdlib.h>
struct tstr_node
{
char dataString[10][30];
struct tstr_node *next;
};
struct tstr_node *head;
int sorted_list_insert(head , pstr_node);
int main()
{
int nod;
struct tstr_node *pstr_node;
nod = sorted_list_insert(*head , pstr_node);
}
int sorted_list_insert(struct tstr_node **head , struct tstr_node *pstr_node)
{
char dataString[30];
pstr_node = (struct tstr_node *)malloc(sizeof(struct tstr_node));
if(pstr_node == NULL)
{
printf("\n Unable to allocate memory! \n");
exit(EXIT_FAILURE);
}
else
{
printf("\n Enter a string for the first node : ");
gets(dataString);
strcpy(pstr_node->dataString, dataString);
pstr_node->next = *head;
*head = pstr_node;
}
return 1;
}