SDL School

API reference / Files, memory, and strings

SDL_LoadFile

Function, SDL3

Reads a full file into new memory, and adds a null character at the end.

Declaration

#include <SDL3/SDL.h>

void * SDL_LoadFile(const char *file, size_t *datasize);

Parameters

fileThe path of the file.
datasizeThe address of a value for the size in bytes, or NULL.

Return value

A pointer to the data, or NULL on failure.

Example

Read a file
file_text = SDL_LoadFile(path, NULL);

See this code run in Read a file. Download the full program (.zip)

Notes

In SDL2

The name is the same.

See also