You're going out of the bounds of your array. Your array is 7 elements long, and it goes from 0 to s-1, where s is its size. If you try to go to the 7th element, you'll be accessing information that you're not meant to, and you may get a segmentation fault (which I think you did!). Change the 8 to a 7 and you'll be fine. :)