#include "stdafx.h"
#include "process.h"
#include "windows.h"
FILE *f,*f1,*f2,*f3,*f4,*f5;
int filesize;
int bubbles(int* mas, int count)
{
int temp;
for (int k=0; k<count; k++)
for (int q=0; q<count-1; q++)
if (mas[q]>mas[q+1]) {temp=mas[q]; mas[q]=mas[q+1]; mas[q+1]=temp;}
return 0;
}
unsigned int WINAPI Thread1 (void *num)
{
int filesize1=50/5;
int mas1[2000];
int i=0;
while (filesize1>0)
{
fscanf_s(f,"%d ", &mas1[i]);
filesize1-=sizeof(mas1[i]);
i++;
}
bubbles(mas1, i);
fopen_s(&f1,"temp1.dat","wt");
for(int k=0; k<i; k++)
fprintf(f1,"%d ",mas1[k]);
return 0;
}
unsigned int WINAPI Thread2 (void *num)
{
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hThreads[5];
unsigned int IDThread0, IDThread1, IDThread2, IDThread3, IDThread4;
hThreads[0] = (HANDLE) _beginthreadex(NULL, 0, Thread1, (void*)2, 0, &IDThread0);
// hThreads[1] = (HANDLE) _beginthreadex(NULL, 0, Thread2, (void*)3, 0, &IDThread1);
//hThreads[2] = (HANDLE) _beginthreadex(NULL, 0, Thread3, (void*)4, 0, &IDThread2);
//hThreads[3] = (HANDLE) _beginthreadex(NULL, 0, Thread4, (void*)5, 0, &IDThread3);
//hThreads[4] = (HANDLE) _beginthreadex(NULL, 0, Thread5, (void*)6, 0, &IDThread4);
fopen_s(&f,"FILE_TO_SORT.DAT", "rt");
fseek(f,0,SEEK_END);
filesize=ftell(f);
printf("\n%d\n",filesize);
fseek(f,0,SEEK_SET);
WaitForSingleObject(hThreads[0],INFINITE);
//WaitForMultipleObjects(2, hThreads, TRUE, INFINITE);
CloseHandle(hThreads);
return 0;
}
Поки що роблю бульбашкою і з одним потоком, щоб хоч трохи розібратися.
Вискакує глюк у
fscanf_s(f,"%d ", &mas1[i]);