the ultimate debugger for segfaults:
Code:
scanf( %d, i )      //if you use scanf, you'd know that you need to 
                           //pass the address of i to scanf, so this line
                           //gives you an illegal operation error(windows)
to find where your program messes up (an you dont have a debugger, too lazy t use it, etc), put this in between every suspicious line of code
Code:
cout << "asdf\n"; fflush( stdout );      //remember to include 
                                                           //stdio.h and iostream.h
then follow through to where your program should go and count how many "asdf" you see on the screen and how many you should see. it works, but its always better to use a debugger.
hope i dont get flamed for this post .