In C SDL2 version 2.0.3, it works with:
fenetre=SDL_GetWindowFromId(touche.windowID); // "touche" is a SDL_KeyboardEvent, "fenetre" is a SDL_window pointer
r_copie=SDL_GetRenderer(fenetre);
s_SnapSource=SDL_CreateRGBSurface(0,SCREEN_WIDTH,SCREEN_HEIGHT,32,
rmask,
gmask,
bmask,
amask); // s_SnapSource is a SDL_Surface pointer
SDL_LockSurface(s_SnapSource);
SDL_RenderReadPixels(r_copie,NULL,s_SnapSource->format->format,
s_SnapSource->pixels,S_SnapSource->pitch);
SDL_SaveBMP(s_SnapSource,NomFichier); // NomFichier is a char*
SDL_UnlockSurface(s_SnapSource);
SDL_FreeSurface(s_SnapSource);
/!\ ATTENTION /!\
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
Uint32 rmask = 0xff000000;
Uint32 gmask = 0x00ff0000;
Uint32 bmask = 0x0000ff00;
Uint32 amask = 0x000000ff;
#else
Uint32 rmask = 0x000000ff;
Uint32 gmask = 0x0000ff00;
Uint32 bmask = 0x00ff0000;
Uint32 amask = 0xff000000;
#endif
...must previously be set somewhere before any use of those variables of course ^^
If you want to put it in a header file make sure you put some "guards" like
#ifndef ENDIANNESS
#define ENDIANNESS
...put the stuff here...
#endif
Otherwise, as said in the comments, you could have multiple definitions error when compiling :{
My bad :{
Don't hesitate to check the functions prototypes for return type and parameter(s), the comments here just giving informations, not more.