#include <Windows.h>
#include <iostream>
#include <fstream>
usingnamespace std;
ofstream outf;
DWORD WINAPI Prime(LPVOID Input)
{
int a = reinterpret_cast<int>(Input);
for (int i=0;i<=a;i++)
{
if(i % 2 != 0 || i % 3 != 0 || i % 5 != 0 )
{
outf << i <<"\n";
}
}
return (DWORD)Input;
}
int main(int argc, char* argv[ ])
{
DWORD ThreadId;
HANDLE ThreadHandle;
int Input;
/* perform some basic error checking */
cout<<"Enter value"<<endl;
cin>>Input;
outf.open("Prime.txt");
ThreadHandle = CreateThread(NULL,0,Prime,&Input,0,&ThreadId); // returns the thread identifier
if (ThreadHandle != NULL)
{
// now wait for the thread to finish
WaitForSingleObject(ThreadHandle, INFINITE);
// close the thread handle
CloseHandle(ThreadHandle);
}
outf.close();
return 0;
}
I want to have a separate thread running the function prime that will take in a number that the user will enter and file output to a .txt file all the prime numbers < = to it. I dont see any real compile errors the the issue is the when i execute the .exe file that creates the txt file; inside the txt is a long list of numbers in order. I also that the input number wasnt taken into account or something please help thanks
i didnt receive any real compiler errors my concern is the output that is being sent to the file, im not sure wat to change in the code for it to stop when its supposed to stop. for some reason it shoots out numbers 1 to 100000+ when i input like for example 100