Help me, im learning SDL right now

i’m sorry my english is not really good enough, so i’m learning sdl right now, and i need some help, maybe it’s simple problem but the problem it’s make me frustated

this is my code :

#include
#include <SDL.h>
#include <stdio.h>

using namespace std;

//screen dimension constant
const int SCREEN_HEIGHT = 480;
const int SCREEN_WIDTH = 640;

//The window we’ll be rendering to
SDL_Window* gWindow = NULL;
//The image we will load and show on the screen
SDL_Surface* gXOut = NULL;
//The surface contained by the window
SDL_Surface* gScreenSurface = NULL;

//Starts up SDL and creates window
bool init();
//load media
bool loadMedia();
//Frees media and shuts down SDL
bool close();

int main(int argc, char* argv[])
{
//Start up SDL and create window
if(!init())
{
cout << “can’t inizialize\n”;
}
else
{
//Load media
if(!loadMedia())
{
cout << “can’t load the media\n”;
}
else
{
//Main loop flag
bool quit= false;

        //Event handler
        SDL_Event e;

        //While application is running
        while(!quit)
        {
            //Handle events on queue
            while(SDL_PollEvent( &e ) != 0)
            {
                //User requests quit
                if(e.type == SDL_QUIT)
                {

                    quit = true;
                }
            }
                //Apply the image
                SDL_BlitSurface(gXOut, NULL, gScreenSurface, NULL);

                //Update the surface
                SDL_UpdateWindowSurface(gWindow);
        }

    }
}

//Free resources and close SDL
close();

}

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

//Initialization flag
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
    cout << "SDL can't initialize\n" << SDL_GetError();
    success = false;
}
else
{
    //Create window
    gWindow = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOWEVENT_SHOWN);
    if(gWindow == NULL)
    {
        cout << "SDL can't make window\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
gXOut = SDL_LoadBMP("test_7/hqdefault");
if(gXOut == NULL)
{
    cout << "can't load the media! error \n" << "test_7/img/hqdefault " << SDL_GetError();
    success = false;
}
return success;

}

bool close()
{
//Deallocate surface
SDL_FreeSurface(gXOut);
gXOut = NULL;

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

//Quit SDL subsystem
SDL_Quit();

}

i dont know why, the picture didn’t show

My guess is that the program can’t find the image that should be loaded.

You haven’t provided a file extension in the SDL_LoadBMP function, which is executed inside the loadMedia function.
Change gXOut = SDL_LoadBMP("test_7/hqdefault");
into gXOut = SDL_LoadBMP("test_7/hqdefault.bmp");
and see if it works.

stil can’t works, but thankyou for helping me , i really frustated

As you can see in the console, the image file still can’t be found. Make sure that the image file is in the correct folder and that the filepath (test_7/hqdefault.bmp) is correct.

  • If you execute the program from within Code::Blocks, make sure that the directory named test_7 is placed in the same directory as your source files (*.h and *.cpp) and that your image file is placed in that test_7 directory.

  • If you execute the program by manually double clicking on the exe file in the Debug folder, make sure that the directory named test_7 is placed in the same directory as your exe file and that your image file is placed in that test_7 directory.

ok, thank you , God Bless You