Reputation: 0 Apprentice
- New Members
- Active Posts:
- 10 (0.01 per day)
- 06-February 09
- Profile Views:
- Last Active:
- Jul 22 2013 11:17 AM
- Dream Kudos:
Posts I've Made
Posted 20 Feb 2012I've never head of malloc taking a second parameter.
Apart from that, I don't see any errors in this piece of code. But memory errors are the hardest kind of errors to debug. First try yo tun your program in a debugger (compile with -g, use gdb ./program, type r for run) and do a backtrace (bt) when you encounter that error, it should allow you to localize where the problem was detected.
If you see no problems there, then your error might have been caused elsewhere. Try running your program with valgrind (compile with -g again, valgrind ./program). Valgrind should be in you package manager. Valgrind is among other things, a memory debugger it will alert you to the typical causes of memory errors. writing past the end of an array, double deletes, using uninitialized values, ....
yes i have included stdlib.h
karel-Lodewijk : i was trying to use calloc insted of malloc and forgot to edit the code sorry for tht..
here's the output of debugger(it works fine till 6th element) :
enter data : 5
enter data : 6
Breakpoint 1, insert (root=0xbffff298, mid=0xbffff28c) at mway_tree.c:200
warning: Source file is more recent than executable.
200 ins(ptr); //push NODE in satke
ins (ptr=0x804c078) at mway_tree.c:52
54 SNODE *var=NULL;
55 var=(SNODE *)malloc(sizeof(SNODE));
*** glibc detected *** /home/utkarsh/Desktop/c-code/Data_structures/trees/a.out: malloc(): memory corruption (fast): 0x0804c038 ***
Posted 19 Feb 2012O and you should probably take a look at what operators have what precedence.
see this link
that solved my problem
but can u pls give detail what was making problem. i didnt get u tht - operator has lower precedence on ->. As i never use -(other than ->)operator.i know m being lame guys but its important for learning right.
- Member Title:
- New D.I.C Head
- Age Unknown
- Birthday Unknown
- Click here to e-mail me
exgenome hasn't added any friends yet.