You will often find people put as much effort into ANSWERING your question as you put into ASKING your question. What most folks will see here is little to no effort. We don't know if this code compile, runs and crashes, works correctly...
We don't know specifically where your misunderstanding is. You didn't even format it in such a way that it could be read by putting the code tags around your source to preserve spacing (I have added them).
If you don't take the time to make it easy for folks to help you, don't be surprised when they don't.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors