peculiar behaviour

Go4Expert Member
12Mar2007,09:41   #1
ganesh_don's Avatar
1.) #include<stdio.h>
2.) #include<malloc.h>

3.) struct node
4.) {
5.) int val;
6.) struct node *next;
7.) };

8.) typedef struct node *Node;

9.) struct stack
10.) {
11.) Node head;
12.) };

13.) typedef struct stack *Stack;

14.) int main()
15.) {
16.) Stack s;
17.) int val;
18.) s->head=NULL;
19.) return 0;
20.) }

Note: line numbers are provided for easy discussion abt the line

Buddies....This program gives me segmentation fault but when i interchanged line 16 and 17 it worked fine.. I dont know wat actually happened.somebody plzz help me....thanks in advance
Go4Expert Founder
12Mar2007,10:32   #2
shabbir's Avatar
You are not allocating the pointer s and so anything can happen which is out of your control.
Go4Expert Member
12Mar2007,16:49   #3
ganesh_don's Avatar
Thankyou buddy......i have been breaking my head for days.Thanks a lot dude...it worked fine.
Go4Expert Founder
12Mar2007,17:09   #4
shabbir's Avatar
Quote:
Originally Posted by ganesh_don
Thankyou buddy......i have been breaking my head for days.Thanks a lot dude...it worked fine.
My pleasure.