A segmentation fault occurs when your program tries to access memory outside of it's memory space. This is often caused by attempting to access NULL pointers, or attempts to access past the end of an array. If you run the code in a debugger, you should be able to find out where the problem is. If the code isn't too long, post it here and I'll have a look.
For future reference, this question would be better suited to the programming forum. Please don't repost it though.