Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C2143: syntax error : missing ';' before '.'

Status
Not open for further replies.

FrankyTheFish

Programmer
Sep 7, 2002
14
0
0
CA
Hey guys, I have a quick question, I'm working with SDL and SDL mixer to get music working in our game. Right now I'm trying to create a way for the users to customize the sounds in the game through a text file.

When using ifstream I'm getting this error, I hgave no idea what started to cause this and was wondering if any of you know what is doing this.

c:\Documents and Settings\FrancoisMessier\My Documents\Drive_F\Drive_F\SDL\sdlBitmaps.cpp(24): error C2143: syntax error : missing ';' before '.'

Thanks for anyone that can take the time to answer these questions. I really appreciate it.

/////////////
the code
////////////

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
#include "SDL.h"
#include "SDL_mixer.h"

using namespace std;
a
/*
For file IO
*/

char ch;
ifstream inFile;
ofstream outFile;

char inputFilename[] = "CTF.txt";
char attackString[] = "phaser.wav";
char musicString[] = "music.ogg";

////////////////////////////////////////
/// the error is for this line below///
//////////////////////////////////////

inFile.open(inputFilename, ios::nocreate);

/*
For file IO
*/

Mix_Chunk *phaser = NULL;
Mix_Music *music = NULL;

int phaserChannel = -1;

void handleKey(SDL_KeyboardEvent key);
void musicDone();

int main(int argc, char *argv[]) {

fileCheck();

SDL_Surface *screen;
SDL_Event event;
int done = 0;

/* Same setup as before */
int audio_rate = 22050;
Uint16 audio_format = AUDIO_S16;
int audio_channels = 2;
int audio_buffers = 4096;

SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);

if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
printf("Unable to open audio!\n");
exit(1);
}

/* Pre-load sound effects */
phaser = Mix_LoadWAV(attackString);

screen = SDL_SetVideoMode(320, 240, 0, 0);

while(!done) {
while(SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_QUIT:
done = 1;
break;
case SDL_KEYDOWN:
case SDL_KEYUP:
handleKey(event.key);
break;
}
}
SDL_Delay(50);

}

Mix_CloseAudio();
SDL_Quit();

}

void handleKey(SDL_KeyboardEvent key) {
switch(key.keysym.sym) {
case SDLK_p:

if(key.type == SDL_KEYDOWN) {

if(phaserChannel < 0) {
phaserChannel = Mix_PlayChannel(-1, phaser, -1);
}
} else {
Mix_HaltChannel(phaserChannel);

phaserChannel = -1;
}
break;
case SDLK_m:
if(key.state == SDL_PRESSED) {
printf("yo");

if(music == NULL) {

music = Mix_LoadMUS(musicString);
Mix_PlayMusic(music, 0);
Mix_HookMusicFinished(musicDone);

} else {
Mix_HaltMusic();
Mix_FreeMusic(music);
music = NULL;
}
}
break;
}
}

void musicDone() {
Mix_HaltMusic();
Mix_FreeMusic(music);
music = NULL;
}

void fileCheck() {


if (! inFile)
{
cout << "Config File non-existant. Now Creating config file... Please wait..." << endl;
fileCreate();
outFile.open();
}
else
{
fileLoad();
inFile.open();
}
}

void fileLoad() {

//char stringRead[50];

attackString = inFile.getline();
musicString = inFile.getline();
inFile.close();
}

void fileCreate() {

outFile.open(inputFilename, ios::eek:ut);
outFile << attackString << endl;
outFile << musicString << endl;
outFile.close();
}
 
You have to put code like that inside a function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top