threading error

Im trying to write a program involving threads.Im just having one error that is annoying me.

23 F:\Lab1.cpp expected primary-expression before ';' token


My code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <windows.h>
#include <iostream>
#define MAX_THREADS 1
using namespace std;
DWORD WINAPI primenum(LPVOID);
int main(int argc, char *argv[])
{
    DWORD ThreadId;
    HANDLE ThreadHandle;
    int num = 0;
    cout<<"Enter a number and it will generate the prime numbers:"<<endl;
    cin>>num;
   
   ThreadHandle = CreateThread(NULL,0,primenum,&num,0,&ThreadId);
   
   for(int i = 0; i < MAX_THREADS; i++) {
   CloseHandle(ThreadHandle);
   }
   return 0;
  
}
DWORD WINAPI primenum(LPVOID n){
      for(DWORD i  = 1; i <= LPVOID; i++)//error line
      {
      if(DWORD(n) % 2 == 0)
                    {
                    cout<<i<<" is a prime number"<< endl;
                 }
      }
      return DWORD(n);
}


any help would be appreciated.
LPVOID is a type, not a value.
ok,changed to
for(DWORD i = 1; i <= n; i++)

now i get:
23 F:\Lab1.cpp ISO C++ forbids comparison between pointer and integer

same line,another error and the rest of the code is the same. any help would be appreciated.

note:sorry to be a pain,but i am really not that good at programming.
You'll need to cast the pointer to a pointer-to-int, then dereference it.
You'll need to cast the pointer to a pointer-to-int, then dereference it.


Yeah.......I have NO IDEA of how to even start doing that. Like i said,I am really,REALLY bad at programming.Im sorry that im being a pain.But can you be a bit more specific.I re-copied the program to at least show that i attempted at doing it.but still can you help me out?



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <windows.h>
#include <iostream>
#define MAX_THREADS 1
using namespace std;
DWORD WINAPI primenum(LPVOID);
int main(int argc, char *argv[])
{
    DWORD ThreadId;
    HANDLE ThreadHandle;
    int num = 0;
    cout<<"Enter a number and it will generate the prime numbers:"<<endl;
    cin>>num;
   
   ThreadHandle = CreateThread(NULL,0,primenum,&num,0,&ThreadId);
   
   for(int i = 0; i < MAX_THREADS; i++) {
   CloseHandle(ThreadHandle);
   }
   return 0;
  
}
DWORD WINAPI primenum(LPVOID n){
      DWORD* n= (DWORD*) &n;
      &n= DWORD;
      for(int i  = 1; i <= n; i++){
      if(DWORD(n) % 2 == 0){
           cout<<i<<" is a prime number"<< endl;
                 }
      }
      return DWORD(n);
}
1
2
3
int* pNum = (int*)n;
for( int i = 1; i <= *pNum; i++ ) { 
  // ... 

Topic archived. No new replies allowed.