create an array of HANDLE objects so that you can put the code in a loop.
const int MaxThreads = 20;
HANDLE hThreads[MaxThreads];
for(int i = 0; i < MaxThreads; i++)
hThreads[i] = (HANDLE)_beginthread(TheThread, 0, NULL);
...
for(int i = 0; i < MaxThreads; i++)
TerminateThread(hThreads[i],0);
Ancient Dragon
Achieved Level 70
32,104 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,574
Skill Endorsements: 68
line 13: you are incrementing i too soon which is causing theThreads[0] to be an uninitialized variable. Move that line down to line 19.
Ancient Dragon
Achieved Level 70
32,104 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,574
Skill Endorsements: 68