i'm facing a error right now on C, using Visual Studio and working with Linked Lists for the first time, i'm trying to make the project a little more structed, and because of that i'm facing some challenges. The error that i'm facing is, when i try to insert an element at a linked list my progam just crashes and give me this error :
Exception generated at 0x500CC944 (ucrtbased.dll) in Lesson_LinkedLists.exe: 0xC0000005: access violation while writing to local 0xCDCDCDCD.
I'm confused with this error, because it really does not support me with enough information so i can search over the internet.
Here are my structs, memory alocation and insert function :
typedef struct Word
{
char Text[Max_Letters];
}*pt_Word;
typedef struct Node_Element
{
pt_Word Word_Data;
struct Node_Element * Next_Node_Element;
}*pt_Node_Element;
typedef struct List
{
char Language[2];
int Number_Words_List;
pt_Node_Element Header;
}*pt_List;
pt_List List_Dynamic_Memory();
pt_Node_Element Node_Dynamic_Memory();
void Insert_Element_Begin(pt_Node_Element Node_Element, pt_List List_Pointer);
int main()
{
int option;
pt_Node_Element Node;
pt_List List;
List = List_Dynamic_Memory();
Node = Node_Dynamic_Memory();
do
{
option = menu();
switch (option)
{
case 1:
{
printf("Diga-me uma palavra : \n");
// fflush(stdin);
gets_s(Node->Word_Data->Text);
Insert_Element_Begin(Node, List);
break;
}
case 2:
{
Display_List(Node, List); break;
}
}
} while (option != 0);
//system("Pause");
}
pt_List List_Dynamic_Memory()
{
pt_List List_Pointer;
List_Pointer = (pt_List)malloc(sizeof(struct List));
List_Pointer->Header = NULL;
List_Pointer->Number_Words_List = 0;
return List_Pointer;
};
pt_Node_Element Node_Dynamic_Memory()
{
pt_Node_Element Node_Pointer;
Node_Pointer = (pt_Node_Element)malloc(sizeof(struct Node_Element));
Node_Pointer->Next_Node_Element = NULL;
return Node_Pointer;
};
void Insert_Element_Begin(pt_Node_Element Node_Element, pt_List List_Pointer)
{
List_Pointer->Number_Words_List++;
if (List_Pointer->Header == NULL)
{
List_Pointer->Header = Node_Element;
Node_Element->Next_Node_Element = NULL;
return;
}
Node_Element->Next_Node_Element = List_Pointer->Header;
List_Pointer->Header = Node_Element;
};
I'm wondering if it's something related to memory alocation, i'm a beginer so i'm sorry if it's a stupid error. Thanks for the help in advance.