Unhandled exception in function

I have this structure;
1
2
3
4
5
typedef struct {
    valueType value;
    struct node*pries;
    struct node *po;
} node;


and if I use it in a function like that
1
2
3
node *temp;
temp = (node*)malloc(sizeof(node));
temp->value= 50;

I get a Unhandled exception at 0x00401419 in doubly_linked_list.exe: 0xC0000005: Access violation writing location 0x00000000. runtime error.
However if I use it in the main function it seems to work well. What the f?
Just post your code...
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
#include <stdio.h>
#include <stdlib.h>

#define valueType int

typedef struct {
    valueType value;
    struct node*pries;
    struct node *po;
} node;

typedef struct {
    node *first;
    node *last;
} doublyLinkedList;

int pushNode(doublyLinkedList tempList, valueType value) //Prideti prie saraso galo elementa
{
    node *temp;

	temp = (node*)malloc(sizeof(node));
    if (temp = NULL)
        return 0;

	temp->value= value;
        /*etc*/
	return 1;
 }
void initNode(doublyLinkedList temp){
	temp.first=NULL;
	temp.last=NULL;
}

int main()
{
	char a;
	doublyLinkedList oTaip= {NULL,NULL};
	initNode(oTaip);
	pushNode(oTaip,111);
    return 0;
}
Embarrassed to say it took a couple of minutes but the problem is here:

if (temp = NULL) //error using assignment operator

should be:
if (temp == NULL)
Ok - now that we have found the fault - there are some things we could look at (not errors really - more a matter of taste?).

#define valueType int
When creating alias names for types - it is customary to use typedef
So typedef int valueType;

Also:
1
2
doublyLinkedList oTaip= {NULL,NULL};
initNode(oTaip); //redundant code - the members of oTaip already initialized in the line above 
no way! thanks!
Topic archived. No new replies allowed.