Answer the question
In order to leave comments, you need to log in
How to fix passing an array to a stream?
An array is passed to the stream (maybe I'm passing it incorrectly), after that I get strange numbers in the stream, although the operations there are not complicated
int *array = new int[mSize];
HANDLE hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)a,&array,0,&tid);
int a(int *array)
{
min = array[0]; max = array[0];
for (i = 0; i < mSize; i++) { sum += array[i]; Sleep(12); }
cout << "Sum :" << sum << endl;
for (i = 0; i < mSize; i++){if (min > array[i]) min = array[i];}
cout << "Min :" << min << endl;
return 0;
}
Answer the question
In order to leave comments, you need to log in
int *array = new int[mSize];
...
HANDLE hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)a,&array,0,&tid);
...
int a(int *array)
&array
with array
, because the variable array
is not an array, but a pointer.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question