exception error emergency!

there is an error in this code can anyone help me ?
error and code here.

At point 0x6C43514F (vcruntime140d.dll), Exception on Exercise.exe occurred: 0xC0000005: 0xCDCDCDCD Violation of write access to the location.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
  #include<iostream>
#include <stdlib.h>
#include <string>
#include <locale.h>
#include <conio.h> 
using namespace std;
typedef struct node {
	string ad, soyad;
	int ogrNo;
	struct node * next;
	struct node * prev;
}OGRENCİ;



OGRENCİ *ilk=NULL, *son=NULL;
void insertNode(string,string,int);
void deleteNode(int);
void displayList();


int main() {
	setlocale(LC_ALL,"Turkish");
	int selection;
	char a;
	char secim;
	while (true)
	{
		

		
		cout << "*** *** ***\n";
		cout << ("      1    -->    insert         \n");
		cout << ("      2    -->    remove         \n");
		cout << ("      3    -->    display         \n");
		/*cout << "Cikis yapmak icin x'ye basiniz." << endl;
		secim = _getch();
		if (secim == 'c' || secim == 'C')
			break;

		system("CLS");*/
		cout << ("*** *** ***\n");
		int z ,flag;
		string x, y;
		cout << ("Seçiiminizi girin: ");
		cin >>selection;
		switch (selection) {
		case 1:
			cout <<("Eklemek istediginiz adı  giriniz:");
			cin>> x;
			cout << ("Eklemek istediginiz adı  giriniz:");
			cin >> y;
			cout << ("Eklemek istediginiz Oğrenci numarasını  giriniz:");
			cin >> z;
			insertNode(x,y,z);
			break;
		case 4 :
			break;
		}
	
	}
		return 0;
	
	
}
//fonksiyonlar
void insertNode(string data, string data2,int data3) {
	OGRENCİ *ptr = (struct node*) malloc(sizeof(struct node));
	if (ptr == NULL) {
		cout<<("Bellekte yeterli alan yok !\n");
		return;
	}
	ptr->ad = data;
	ptr->soyad = data2;
	ptr->ogrNo = data3;
	ptr->next = NULL;

	if (ilk == NULL) 
		ilk = son = ptr;
	else {
		son->next = ptr;
		son = ptr;
	}
}
void deleteNode(int x) {
	if (ilk == NULL)
	{
		cout <<("Listede hic eleman yok !\n");
		return;
	}
	else {
		struct node *p;
		struct node *previous = ilk;
		for (p = ilk; p != NULL; p = p->next) //listeyi geziyoruz
		{
			if (p->ogrNo == x) //eleman bulundu
			{

				//case1:ilk eleman silinmek isteniyor
				if (p == ilk)
				{
					ilk = ilk->next;
					free(p);
					cout<<"işlem başarıyla silindi"<<endl;
					return;
				}
				//case2:son eleman silinmek isteniyor
				if (p == son) {
					previous->next = p->next; //p->next=NULL zaten
					son = previous;
					free(p);
					cout << "işlem başarıyla silindi" << endl; 
					return;
				}
				//case3:aradan eleman silinmek isteniyor
				previous->next = p->next;
				free(p);
				cout << "işlem başarıyla silindi" << endl;
				return;
			}
			previous = p;
		}

		//for bitti ama hala return etmedi yani eleman bulunamadi
		cout << "aranan eleman bulunmadı" << endl;
		return;
	}
}
void displayList() {
	struct node *ptr = ilk;

	

	
	cout << "\n elemanlar";
	while (ptr != NULL) {
		cout << ptr->ad;
		cout << ptr->soyad;
		cout << ptr->ogrNo;
		ptr = ptr->next;
	}
	cout<<(" ]\n");

}
You're using C++ (template) classes like std::string. You cannot use malloc with them - you need to allocate memory in the C++ way, using new (and delete to free them).
To elaborate on MikeyBoy's answer, consider a class with a constructor and destructor. If you allocate space for them with malloc(), the constructor won't get called. And if you use free() to deallocate, the destructor won't get called.

Also, you have a prev pointer but you don't use it. Either remove the prev pointer or use it.
Topic archived. No new replies allowed.