Code Runs output flashes and disappears

I am learning SDL and am able to execute this code, but can’t get to see the output.
I tried changing the number inside “SDL_Delay( 200000 );” - but to no avail.

Code:
/This source code copyrighted by Lazy Foo’ Productions (2004-2013)
and may not be redistributed without written permission.
/

//Using SDL and standard IO
#include <SDL.h>
#include <stdio.h>

//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

//Starts up SDL and creates window
bool init();

//Loads media
bool loadMedia();

//Frees media and shuts down SDL
void close();

//The window we’ll be rendering to
SDL_Window* gWindow = NULL;

//The surface contained by the window
SDL_Surface* gScreenSurface = NULL;

//The image we will load and show on the screen
SDL_Surface* gHelloWorld = NULL;

bool init()
{
//Initialization flag
bool success = true;

//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
	printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
	success = false;
}
else
{
	//Create window
	gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
	if( gWindow == NULL )
	{
		printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
		success = false;
	}
	else
	{
		//Get window surface
		gScreenSurface = SDL_GetWindowSurface( gWindow );
	}
}

return success;

}

bool loadMedia()
{
//Loading success flag
bool success = true;

//Load splash image
gHelloWorld = SDL_LoadBMP( "02_getting_an_image_on_the_screen/hello_world.bmp" );
if( gHelloWorld == NULL )
{
	printf( "Unable to load image %s! SDL Error: %s\n", "02_getting_an_image_on_the_screen/hello_world.bmp", SDL_GetError() );
	success = false;
}

return success;

}

void close()
{
//Deallocate surface
SDL_FreeSurface( gHelloWorld );
gHelloWorld = NULL;

//Destroy window
SDL_DestroyWindow( gWindow );
gWindow = NULL;

//Quit SDL subsystems
SDL_Quit();

}

int main( int argc, char* args[] )
{
//Start up SDL and create window
if( !init() )
{
printf( “Failed to initialize!\n” );
}
else
{
//Load media
if( !loadMedia() )
{
printf( “Failed to load media!\n” );
}
else
{
//Apply the image
SDL_BlitSurface( gHelloWorld, NULL, gScreenSurface, NULL );

		//Update the surface
		SDL_UpdateWindowSurface( gWindow );

		//Wait two seconds
		SDL_Delay( 200000 );
	}
}

//Free resources and close SDL
close();

return 0;

}

gHelloWorld = SDL_LoadBMP( “02_getting_an_image_on_the_screen/hello_world.bmp” );

You need to have a file called hello_world.bmp in a folder named 02_getting_an_image_on_the_screen in the same folder you have your exe.

volvam wrote:> I am learning SDL and am able to execute this code, but can’t get to see the output.

I tried changing the number inside “SDL_Delay( 200000 );” - but to no avail.

You are telling it to find a file named hello_world.bmp at /02_getting_an_image_on_the_screen/

If its not in that specific folder you are telling it to find the file then it will not find the file.

volvam wrote:>

AlexRou wrote:

gHelloWorld = SDL_LoadBMP( “02_getting_an_image_on_the_screen/hello_world.bmp” );

You need to have a file called hello_world.bmp in a folder named 02_getting_an_image_on_the_screen in the same folder you have your exe.

volvam wrote:

I am learning SDL and am able to execute this code, but can’t get to see the output.
I tried changing the number inside “SDL_Delay( 200000 );” - but to no avail.

I’ve already put in the folder and tried again, but the same thing happens
https://app.box.com/s/253zbq3y2904bugeh72y

Is this looking good?

BTW are you new to programming in general? Cuz if you are, you would be better off learning how to program before even thinking of touching SDL.

volvam wrote:>

AlexRou wrote:

You are telling it to find a file named hello_world.bmp at /02_getting_an_image_on_the_screen/

If its not in that specific folder you are telling it to find the file then it will not find the file.

volvam wrote:

AlexRou wrote:

gHelloWorld = SDL_LoadBMP( “02_getting_an_image_on_the_screen/hello_world.bmp” );

You need to have a file called hello_world.bmp in a folder named 02_getting_an_image_on_the_screen in the same folder you have your exe.

volvam wrote:

I am learning SDL and am able to execute this code, but can’t get to see the output.
I tried changing the number inside “SDL_Delay( 200000 );” - but to no avail.

I’ve already put in the folder and tried again, but the same thing happens
https://app.box.com/s/253zbq3y2904bugeh72y

Is this looking good?

Awesome, thanks a ton Sir!

AlexRou wrote:

gHelloWorld = SDL_LoadBMP( “02_getting_an_image_on_the_screen/hello_world.bmp” );

You need to have a file called hello_world.bmp in a folder named 02_getting_an_image_on_the_screen in the same folder you have your exe.

volvam wrote:

I am learning SDL and am able to execute this code, but can’t get to see the output.
I tried changing the number inside “SDL_Delay( 200000 );” - but to no avail.

I’ve already put in the folder and tried again, but the same thing happens
https://app.box.com/s/253zbq3y2904bugeh72y

Is this looking good?

AlexRou wrote:

You are telling it to find a file named hello_world.bmp at /02_getting_an_image_on_the_screen/

If its not in that specific folder you are telling it to find the file then it will not find the file.

volvam wrote:

AlexRou wrote:

gHelloWorld = SDL_LoadBMP( “02_getting_an_image_on_the_screen/hello_world.bmp” );

You need to have a file called hello_world.bmp in a folder named 02_getting_an_image_on_the_screen in the same folder you have your exe.

volvam wrote:

I am learning SDL and am able to execute this code, but can’t get to see the output.
I tried changing the number inside “SDL_Delay( 200000 );” - but to no avail.

I’ve already put in the folder and tried again, but the same thing happens
https://app.box.com/s/253zbq3y2904bugeh72y

Is this looking good?

Awesome, thanks a ton Sir!