error C2143: syntax error : missing ';' before 'constant' - visual-c++

Hi i am trying to use microsofts visual studio 2010 to make a text based game the only problem is when i made some functions it gave me this error when i wanted to run it error C2143: syntax error : missing ';' before 'constant' i can't figure it out. here is the script this is in c++
// Text Game.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdlib.h>
void ShowIntroduction ( void )
{
printf( "Hello welcome to this text-based adventure game.\n" );
printf( "In this adventure game we will run into many difficult situations\n" );
printf( "1. A situation will present it's self\n" );
printf( "2. You will be given some choices.\n" );
printf( "3. You will need to make some choices.\n" );
printf( "4. The result of your choice will be shown.\n" );
}
void ShowSituation1 ( void )
{
printf( "\n\nYou are walking down a loney, dusty road.\n" );
printf( "When you see a gem on the ground.\n" );
printf( "It is bright and shiny!!\n" );
}
void ShowSituation2 ( void )
{
printf( "\n\nThe cave entrance looks inviting.\n" );
printf( "You are tempted to enter.\n" );
printf( "It looks kind of dark.\n" );
}
void ShowSituation3 ( void )
{
printf( "\nDo you want to keep going?\n" );
}
void ShowChoices1 ( void )
{
printf( "\nHere are your choices\n" );
printf( "1. Pick up the gem.\n");
printf( "2. Kick the gem off the road.\n" );
printf( "3. Stomp on the gem.\n" );
}
void ShowChoices2 ( void )
{
printf( "\nHere are your choices.\n" );
printf( "1. Run away\n" );
printf( "2. Take a nap.\n" );
printf( "3. Slowly enter the cave.\n" );
}
void ShowChoices3 ( void )
{
printf( "\n1. Ya I ain't scared.\n" );
printf( "2. No I need my mommy.\n" );
}
int GetChoice ( int min, int max)
{
int Choice;
do
{
printf( "Your choice? " );
scanf( "%d", &Choice );
}
while( Choice < min || Choice > max );
return( Choice );
}
void ShowResults1 ( int Choice )
{
if( Choice == 1 )
{
printf( "\nYou pick up the gem and put it in your backpack.\n" );
printf( "You start walking down the road when you see smoke coming from your backpack.\n" );
printf( "Quickly you throw your bag off and jump down the hill just in time to escape the explosin from your bag.\n" );
printf( "You continue to roll down the hill, when you finally stop you get up and find a cave.\n" );
}
else if( Choice == 2 )
{
printf( "\nThe gem flys off the road.\n" );
printf( "You decide to see if you can find where it landed.\n" );
printf( "When you reach the bottom you notice a cave.\n" );
}
else if( Choice == 3 )
{
printf( "\nThe gem sends you sky high.\n" );
printf( "You hope that your health insurance is up to date.\n" );
printf( "Lucky for you it was a nice grassy hill you landed on.\n" );
printf( "You stand up to figure out where you are.\n" );
printf( "You notice a cave.\n" );
}
else
{
printf( "\nThat wasn't a Choice you bozo.\n" );
printf( "You are dead now!!\n" );
exit (0);
}
}
void ShowResults2 ( int Choice )
{
if( Choice == 1 )
{
printf( "\nWhat a chicken.\n" );
printf( "Looks like you need your mommy.\n" );
exit 0;
}
else if( Choice == 2 )
{
printf( "\nIt is night time when you awake.\n" );
printf( "You get up and start walking but don't make it far.\n" );
printf( "You were attacked by a pack of wolves.\n" );
exit 0;
}
else if( Choice == 3 )
{
printf( "You enter the cave slowly.\n" );
printf( "Your only light sorce is a lighter in your pocket.\n" );
printf( "You find a torch on the wall, you get the torch lit.\n" );
}
else
{
printf( "\nThat wasn't a Choice you bozo.\n" );
printf( "You are dead now!!\n" );
exit (0);
}
}
void ShowResults3 ( int Choice )
{
if( Choice == 1 )
{
printf( "\nYou decide to keep going.\n" );
}
else if( Choice == 2 )
{
printf( "\nWhat a pussy you are!!\n" );
exit 0;
}
else
{
printf( "\nThat wasn't a Choice you bozo.\n" );
printf( "You are dead now!!\n" );
exit (0);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int Choice;
ShowIntroduction ();
ShowSituation1 ();
ShowChoices1 ();
Choice = GetChoice ( 1,3 );
ShowResults1 ( Choice );
ShowSituation2 ();
ShowChoices2 ();
Choice = GetChoice ( 1,3 );
ShowResults2 ( Choice );
ShowSituation3 ();
ShowChoices3 ();
Choice = GetChoice ( 1,3 );
ShowResults3 ( Choice );
return 0;
}

It's exit(0), not exit 0.
You could have narrowed this down really easily. Also please next time check the formatting of your post before you submit: there is a preview pane on the Ask Question page.

Related

Unhandled exception at 0x000007FEDF2C9120 (gdal202.dll) in GdalTest.exe: 0xC0000005: Access violation reading location 0x0000000000000058

I try using CreateCopy(), it seem in thrown me an exception when i run the program
Unhandled exception at 0x000007FEDF2C9120 (gdal202.dll) in GdalTest.exe: 0xC0000005: Access violation reading location 0x0000000000000058.
It will display this output on the console:
I try debug on the exception occurs, on the call stack it will go to the new tab then display no symbol loaded
I hope someone can explain to me what file not be loaded and if the console can view raster map it is will throw an error or exception ?
Below is my code if someone want to copy and make reference it just i have issues on "Using CreateCopy()" part.
Thank you and best regards,
// GdalTest.cpp : Defines the entry point for the console application.
//
#include "cpl_conv.h" // for CPLMalloc()
#include "stdafx.h"
#include "gdal.h"
#include <stdlib.h>
#include <stdio.h>
#include "iostream"
#include "cpl_string.h"
#include "gdal_priv.h"
class GDALMajorObject;
class GDALDataset;
class GDALRasterBand;
class GDALDriver;
class GDALRasterAttributeTable;
class GDALProxyDataset;
class GDALProxyRasterBand;
class GDALAsyncReader;
int main(int argc,char* argv)
{
///*/*/*/*/*/*/*/*/*/*Getting Dataset Information*/*/*/*/*/*/*/*/*/*/
GDALDataset *poDataset;
//GDALDatasetH *poDatasetH;
const char* Raster = new char[256];
double adfGeoTransform[6];
GDALAllRegister();
Raster = "C:\\Users\\User\\Desktop\\DSI REFERENCE\\Map Data\\Raster\\4257.tif";
poDataset = (GDALDataset *) GDALOpen(Raster, GA_ReadOnly )CPL_WARN_UNUSED_RESULT;
//poDataset = (GDALDataset *) GDALOpen(Raster, GA_ReadOnly );
if( poDataset == NULL )
{
printf("Not found");
}
else
{
printf( "Driver: %s/%s\n",
poDataset->GetDriver()->GetDescription(),
poDataset->GetDriver()->GetMetadataItem( GDAL_DMD_LONGNAME ) );
printf( "Size is %dx%dx%d\n",
poDataset->GetRasterXSize(), poDataset->GetRasterYSize(),
poDataset->GetRasterCount() );
if( poDataset->GetProjectionRef() != NULL )
printf( "Projection is `%s'\n", poDataset->GetProjectionRef() );
if( poDataset->GetGeoTransform( adfGeoTransform ) == CE_None )
{
printf( "Origin = (%.6f,%.6f)\n",
adfGeoTransform[0], adfGeoTransform[3] );
printf( "Pixel Size = (%.6f,%.6f)\n",
adfGeoTransform[1], adfGeoTransform[5] );
}
}
///*/*/*/*/*/*/*/*/*/* Fetching a Raster Band*/*/*/*/*/*/*/*/*/*/
GDALRasterBand *poBand;
int nBlockXSize, nBlockYSize;
int bGotMin, bGotMax;
double adfMinMax[2];
poBand = poDataset->GetRasterBand( 1 );
poBand->GetBlockSize( &nBlockXSize, &nBlockYSize );
printf( "Block=%dx%d Type=%s, ColorInterp=%s\n", nBlockXSize, nBlockYSize,GDALGetDataTypeName(poBand->GetRasterDataType()),
GDALGetColorInterpretationName( poBand->GetColorInterpretation()) );
adfMinMax[0] = poBand->GetMinimum( &bGotMin );
adfMinMax[1] = poBand->GetMaximum( &bGotMax );
if( ! (bGotMin && bGotMax) )
GDALComputeRasterMinMax((GDALRasterBandH)poBand, TRUE, adfMinMax);
printf( "Min=%.3fd, Max=%.3f\n", adfMinMax[0], adfMinMax[1] );
if( poBand->GetOverviewCount() > 0 )
printf( "Band has %d overviews.\n", poBand->GetOverviewCount() );
if( poBand->GetColorTable() != NULL )
printf( "Band has a color table with %d entries.\n",
poBand->GetColorTable()->GetColorEntryCount() );
// make it 256 bytes for a string length of 255 plus null (\0) terminator
///*/*/*/*/*/*/*/*/*/*/*Reading Raster Data*/*/*/*/*/*/*/*/*/*/*/
float *pafScanline;
int nXSize = poBand->GetXSize();
pafScanline = (float *) CPLMalloc(sizeof(float)*nXSize);
poBand->RasterIO( GF_Read, 0, 0, nXSize, 1,pafScanline, nXSize, 1, GDT_Float32,0, 0 );
///*/*/*/*/*/*/*/*/*/*/*Techniques for Creating Files (determine whether it supports Create() and/or CreateCopy().) */*/*/*/*/*/*/*/*/*/*/
const char *pszFormat = "GTiff";
GDALDriver *poDriver;
char **papszMetadata;
poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat);
if( poDriver == NULL )
exit( 1 );
papszMetadata = poDriver->GetMetadata();
if( CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATE, FALSE ) )
printf( "Driver %s supports Create() method.\n", pszFormat );
if( CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATECOPY, FALSE ) )
printf( "Driver %s supports CreateCopy() method.\n", pszFormat );
///*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*Using CreateCopy()*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
const char*pszDstFilename= new char[256];
GDALDataset *poSrcDS =(GDALDataset *) GDALOpen( pszDstFilename, GA_ReadOnly );
GDALDataset *poDstDS;
poDstDS = poDriver->CreateCopy( pszDstFilename, poSrcDS, FALSE,NULL, NULL, NULL );
/* Once we're done, close properly the dataset */
if( poDstDS != NULL )
GDALClose( (GDALDatasetH) poDstDS );
GDALClose( (GDALDatasetH) poSrcDS );
std::cin.get();
//delete[] Raster;// release the memory VERY IMPORTANT
}
You haven't set the variable pszDstFilename to anything meaningful. You allocated it, but it just contains random junk. You need to put a valid existing dataset into it for anything useful to happen in the call to GDALOpen(). The documentation states:
Once the drivers are registered, the application should call the free standing GDALOpen() function to open a dataset, passing the name of the dataset and the access desired (GA_ReadOnly or GA_Update).

Why is PostThreadMessage() giving me an unlisted error message ERROR_MESSAGE_SYNC_ONLY?

In an MFC application that has to process user events in real time, a sub-thread is created to do some lengthy math processing. However, sending it a message results in error 1159, which winerror.h reveals to be ERROR_MESSAGE_SYNC_ONLY. Why?
Thread creation:
#define MATHTHREAD_PROC ( 1 )
hMathThread = CreateThread( 0, 0, MathThreadProc, this, 0, &dwMathThreadID );
if( !hMathThread )
printf( "Math CreateThread() fail\n" );
Thread signalling:
if ( !PostThreadMessage( dwMathThreadID, MATHTHREAD_PROC, NULL, 0 ) ) {
DWORD dwError = GetLastError();
printf( "PostThreadMessage() for math thread: %d\n", dwError );
}
Thread code:
static DWORD WINAPI MathThreadProc( LPVOID pvUserData ) {
return ( (MyClass*) pvUserData )->MathThread();
}
DWORD MyClass::MathThread() {
MSG msg;
int iRV;
// https://msdn.microsoft.com/en-us/library/ms644946(v=vs.85).aspx
iRV = PeekMessage( &msg, NULL, WM_USER, WM_USER, PM_NOREMOVE );
while ( iRV = GetMessage( &msg, 0, 0, 0 ) ) {
if ( iRV == -1 )
printf( "GetMessage() = -1: %d\n", GetLastError() );
switch ( msg.message ) {
case MATHTHREAD_PROC:
ProcessMath();
break;
default:
printf( "got math thread exit request %p\n", this );
abort();
}
}
printf( "SCGraph::MathThread(): GetMessage = WM_QUIT\n" );
return msg.wParam;
}
ERROR_MESSAGE_SYNC_ONLY means that the message is below WM_USER. Just changing the message ID causes the post to work:
#define MATHTHREAD_PROC ( WM_USER + 1 )

waveOutOpen(), waveOutWrite() gives my thread undocumented message 1024

The sound output functions are giving me unexpected messages. Is this a sign I'm doing something wrong? If so what? Otherwise is there a good source that explains what these messages might be?
waveOutOpen() gives me message 955 MM_WOM_OPEN as documented, followed by an undocumented 1024 (possibly DDM_SETFMT, DM_GETDEFID, NIN_SELECT, TBM_GETPOS, WM_PSD_PAGESETUPDLG, WM_USER, according to https://wiki.winehq.org/List_Of_Windows_Messages).
In main thread:
hAudioOut = CreateThread( 0, 0, AudioOutThreadProc, this, 0, &dwAudioOutId );
if( !hAudioOut ) {
AKS( AKSWarn, "Audio Out CreateThread() fail" );
return;
}
In the resulting audio thread:
static DWORD WINAPI AudioOutThreadProc( LPVOID lpParameter ) {
Interpreter* pinterp = (Interpreter *) lpParameter;
WAVEFORMATEX waveFormat;
waveFormat.cbSize = sizeof(waveFormat);
waveFormat.wFormatTag = WAVE_FORMAT_PCM;
waveFormat.nChannels = 1;
waveFormat.nSamplesPerSec = (int) dFreqEval;
waveFormat.wBitsPerSample = iOutputBits;
waveFormat.nBlockAlign = waveFormat.nChannels *
waveFormat.wBitsPerSample / 8;
waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec *
waveFormat.nBlockAlign;
MMRESULT openRes = waveOutOpen( &waveOut, WAVE_MAPPER, &waveFormat,
(DWORD_PTR) dwAudioOutId, (DWORD_PTR) this,
CALLBACK_THREAD /*| WAVE_FORMAT_DIRECT*/ );
if ( openRes != MMSYSERR_NOERROR )
Log( "waveOutOpen() = %d", openRes );
MSG msg;
int iRV;
while ( iRV = GetMessage( &msg, 0, 0, 0 ) ) {
Log( "got message %d", msg.message );
// Is the main thread asking us to stop?
if ( pinterp->bStop ) {
Log( "AudioInThreadProc(): bStop" );
return EXIT_SUCCESS;
}
// Did we get an error?
if ( iRV == -1 ) {
Log( "GetMessage() = -1: %d", GetLastError() );
abort();
}
// Did we get an expected message? (Only one expected,
// which tells us its time to write more data.)
if ( msg.message == WOM_DONE )
pinterp->Write();
// Anything else--log it.
else
Log( "got unknown message %d", msg.message );
}
Log( "AudioInThreadProc(): GetMessage = return" );
return msg.wParam;
}
waveOutWrite() isn't documented to give any messages, but is giving me message 1024 as well.

SDL2/GL context defaults to v3.0 on linux mint

When I compile & run my code to create an opengl 3.3 or above context (identical to the windows version, with one or two extra lines), it defaults to 3.0, which will cause problems with some of my applications I want to port over.
I'm looking for a fix/explanation of this.
Source as follows:
//Using SDL and standard IO
#include <SDL2/SDL.h>
#include <stdio.h>
#include <GL/glew.h>
//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
bool handleEvent(SDL_Event& event)
{
return true;
}
int main( int argc, char* args[] )
{
//The window we'll be rendering to
SDL_Window* window = NULL;
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
}
else
{
//Create window
window = SDL_CreateWindow("SDL/GLM/OpenGL Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN );
if( window == NULL )
{
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
}
else
{
SDL_GLContext context = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, context);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetSwapInterval(1); // set swap buffers to sync with monitor's vertical refresh rate
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glewExperimental = GL_TRUE;
glClearColor(1.0,0.0,0.0,1.0);
GLenum err = glewInit();
if (err != GLEW_OK)
{
printf("glew init failed: %s!\n", glewGetErrorString(err));
}
printf("opengl version :%s\n",glGetString(GL_VERSION));
bool running = true; // set running to true
SDL_Event sdlEvent; // variable to detect SDL events
while (running)
{ // the event loop
while (SDL_PollEvent(&sdlEvent))
{
if (sdlEvent.type == SDL_QUIT)
running = false;
else
{
running = handleEvent(sdlEvent);
}
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SDL_GL_SwapWindow(window);
}
SDL_GL_DeleteContext(context);
SDL_DestroyWindow(window);
}
}
SDL_Quit();
return 0;
}
You need to set GL attributes before you create a window, not after you create a context:
SDL_GL_SetAttribute()
Use this function to set an OpenGL window attribute before window creation.
Example:
#include <GL/glew.h>
#include <SDL2/SDL.h>
#include <iostream>
int main( int argc, char** argv )
{
SDL_Init( SDL_INIT_EVERYTHING );
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_Window* window = SDL_CreateWindow
(
"SDL2",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
300, 300,
SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL
);
if( NULL == window )
{
std::cerr << "Failed to create window: " << SDL_GetError() << std::endl;
SDL_Quit();
return 0;
}
SDL_GLContext context = SDL_GL_CreateContext(window);
if( NULL == context )
{
std::cerr << "Failed to create GL context: " << SDL_GetError() << std::endl;
SDL_DestroyWindow( window );
SDL_Quit();
return -1;
}
if( SDL_GL_MakeCurrent( window, context ) < 0 )
{
std::cerr << "Failed to make GL context current: " << SDL_GetError() << std::endl;
SDL_GL_DeleteContext( context );
SDL_DestroyWindow( window );
SDL_Quit();
return -1;
}
std::cout << "GL_VERSION: " << glGetString( GL_VERSION ) << std::endl;
SDL_GL_SetSwapInterval(1);
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if( GLEW_OK != err )
{
std::cerr << "Failed init GLEW: " << glewGetErrorString( err ) << std::endl;
SDL_GL_DeleteContext( context );
SDL_DestroyWindow( window );
SDL_Quit();
return -1;
}
bool running = true;
while( running )
{
SDL_Event ev;
while( SDL_PollEvent( &ev ) )
{
if ( ev.type == SDL_QUIT )
running = false;
}
glClear( GL_COLOR_BUFFER_BIT );
SDL_GL_SwapWindow( window );
}
SDL_GL_DeleteContext( context );
SDL_DestroyWindow( window );
SDL_Quit();
return 0;
}
As it turns out, mesa drivers do not support OpenGL contexts above 3.0, so the driver will default to the maximum available, which is 3.0. In order to create a 3.x context, you must have proprietary drivers installed. Once I had installed those drivers everything worked fine.

Perl thread kill doesn't work

I was playing with this code, from the way the beep is sounding, once the program starts it doesn't stop. I suspect the problem is with $thread->kill('KILL')->detach;.
Any ideas? Or have I done something wrong ?
#!c:/perl/bin/perl
use threads;
use Audio::Beep;
my $thread;
my $playing=0;
while (1) {
my $val = int( rand(10) );
print "$val\n";
# if event "start" occurs and is not playing create thread
#if ( ($val==0 || $val==1 || $val==2 || $val==3 || $val==4 ) && (!$playing) ) {
if ( ($val==0 || $val==1 || $val==2 ) && (!$playing) ) {
$playing = 1;
$thread = threads->create(
sub {
local $SIG{'KILL'} = sub { threads->exit() };
print "start beep\n";
beep( 520, 10000 );
}
);
}
# if event "end" occurs and playing wait 1 seconf and kill thread
elsif ( ($val==5 ) && $playing ) {
print "stop beep \n";
#sleep(1);
$playing = 0;
$thread->kill('KILL')->detach;
}
#sleep(1);
$count = 0;
for($i=0; $i<99999 ; $i++) {
$count++;
}
}
I think your program is mostly working as you intend. One of the problems with what I see now is that every beep sounds alike. I re-wrote it a little to give the beep some texture, and to slow things down so that you can appreciate what's happening.
Also, as you've written it, there's a possibility that the thread will end on its own, before you can kill it. I've made the thread persistent, and added additional diagnostic information which will confirm when the thread is running and when it is not.
use strict;
use warnings;
use threads;
use Audio::Beep;
my $thread;
my $playing=0;
while (1) {
my $val = int( rand(30) );
print "$val\n";
my $running = threads->list(threads::running);
print "Threads running: $running\n";
# if event "start" occurs and is not playing create thread
if ( ( $val==1 ) && (!$playing) ) {
$playing = 1;
print ">>>>>>>>\n";
sleep(1);
$thread = threads->create(
sub {
local $SIG{'KILL'} = sub { threads->exit() };
print "start beep\n";
while (1) {
beep( 520, 100 );
sleep(1);
beep( 3800, 100 );
sleep(1);
beep( 2000, 100);
sleep(1);
}
}
);
}
# if event "end" occurs and playing wait 5 seconds and kill thread
elsif ( ($val==2 ) && $playing ) {
print "STOPSTOPSSTOPSTOPSTOP\n";
sleep(5);
$thread->kill('KILL')->detach;
$playing = 0;
}
for(my $i=0; $i<999999 ; $i++) {}
}

Resources