sunnyjain
sunnyjain

Reputation:

simple thread work in c++

I am creating a simple C++ program to ask user for fahrenheit in main thread and then convert this value to Celsius in another thread.

But i continue to get one error . This error keeps

visual studio 2008\projects\cs1\cs1\cs1.cpp(16) : error C2143: syntax error : missing ';' before '='

This problem sometimes disappears but instead of that a run time exception appears. I am using Visual studio 2008, windows XP.

thanks -Sunny Jain

#include "stdafx.h"
#include "stdafx.h"
#include "windows.h"
#include "stdlib.h"
#include "stdio.h"
#include "process.h"
#include "conio.h"
#include "iostream"
using namespace std;

bool flag= false;

void calculateTemperature_DegreeCelcius(void * Fahrenheit)
{
    float far;
    far=*((float*) Fahrenheit);
    float celcius = (5.0/9.0)*(far - 32);
    cout << "\nDegree Celcius :";
    cout << celcius;  
    flag = true;
}


int _tmain(int argc, _TCHAR* argv[])
{
    float temp_Fahrenheit;

    while(true){
        cout << "\nEnter Degree Fahrenheit value you want to convert to Degree Celcius\n";
        cout << "Degree Fahrenheit :";     
        cin >> temp_Fahrenheit;
        _beginthread(calculateTemperature_DegreeCelcius, 0, &temp_Fahrenheit);
    while(true){
        if(flag==false){
            Sleep(200);
        } else {
            break;
        }
    }

    char *command = (char *)NULL;
    cout<< "\nDo you want to continue ? yes/no :";
    cin>> command;

    if (strcmp("yes",command)){
        flag = false;
    } else {
        break;
    }
    }
    return 0;
}

Upvotes: 0

Views: 909

Answers (2)

plinth
plinth

Reputation: 49189

In many C/C++ compilers, especially Microsoft ones, far is a reserved word (either keyword or defined in a header).

Upvotes: 12

M1EK
M1EK

Reputation: 820

far is a #define in WinDef.h

#define far
#define near
#if (!defined(_MAC)) && ((_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED))
#define pascal __stdcall
#else
#define pascal
#endif

Upvotes: 6

Related Questions