Unfortunately I am not entirely sure what you mean in some areas of your post, however if you want to count the number of times a loop is executed, you are better off using a for than a while loop, so instead of:
Code:
while (condition)
{
stuff;
}
you could do
Code:
int i;
for (i = 1; condition; i++)
{
stuff;
}
If you are hung up on using while though, you could do:
Code:
int i;
i = 1;
while (condition)
{
stuff;
i++;
}
As for the "windows box terminates" problem, I presume you mean a DOS command window: try putting just before the return line of the main function.