- #include <stdio.h>
#include <stdlib.h>
#include <process.h>
typedef struct {int x, y, z; } POINT;
void DisplayPoint(void * datum)
{
POINT *P = (POINT *) datum;
printf("\n Point=(%4d,%4d)\n", P->x, P->y, P->z);
_endthread();
}
POINT MakePoint(int x, int y, int z)
{
POINT P;
P.x = x;
P.y = y;
P.z = z;
return P;
// notice this is passed back by value.
}
int main(int argc, char* argv[])
{
int i;
POINT A[10];
// Array of Points
for(i=0; i<10; i++)
// Initialize points: (1,1,1)...(9,9,9)
{
A[i] = MakePoint(i, i, i); // value is
copied into A[i].
_beginthread(DisplayPoint, 0, (void *) &A[i]);
}
-
while ( getchar() != 'c')
; // wait for user to type
'c'
return 0;
}
|