---
name: "load_datafile"
section: "3alleg"
platform: "linux"
package: "liballegro-doc"
version: "2:4.2.2-2.2"
release: "Debian 6.0 (Squeeze)"
platforms: ["linux"]
url: "https://new.carta.tech/load_datafile"
---

# load\_datafile(3alleg)

Loads a datafile into memory. Allegro game programming library.

## NAME

load\_datafile - Loads a datafile into memory. Allegro game programming library.

## SYNOPSIS

**#include \<allegro.h\>**

**DATAFILE \*load\_datafile(const char \*filename);**

## DESCRIPTION

Loads a datafile into memory in one go. If the datafile has been encrypted, you must first call packfile\_password() to set the appropriate key. If the datafile contains truecolor graphics, you must set the video mode or call set\_color\_conversion() before loading it. Example:

```
   /* Load the resources for our game. */
   DATAFILE *dat = load_datafile("game.dat");
   if (!dat)
      abort_on_error("Couldn't load sound resources!");
   /* Use resources. */
   ...
   /* Destroy them when we don't need them any more. */
   unload_datafile(dat);
```

## RETURN VALUE

Returns a pointer to the DATAFILE, or NULL on error. Remember to free this DATAFILE later to avoid memory leaks.

## SEE ALSO

[**load\_datafile\_callback**(3alleg)](/load_datafile_callback/3alleg.md), [**unload\_datafile**(3alleg)](/unload_datafile/3alleg.md), [**load\_datafile\_object**(3alleg)](/load_datafile_object/3alleg.md), [**set\_color\_conversion**(3alleg)](/set_color_conversion/3alleg.md), [**fixup\_datafile**(3alleg)](/fixup_datafile/3alleg.md), [**packfile\_password**(3alleg)](/packfile_password/3alleg.md), [**find\_datafile\_object**(3alleg)](/find_datafile_object/3alleg.md), [**register\_datafile\_object**(3alleg)](/register_datafile_object/3alleg.md), [**excustom**(3alleg)](/excustom/3alleg.md), [**exdata**(3alleg)](/exdata/3alleg.md), [**exexedat**(3alleg)](/exexedat/3alleg.md), [**exgui**(3alleg)](/exgui/3alleg.md), [**exsprite**(3alleg)](/exsprite/3alleg.md), [**exunicod**(3alleg)](/exunicod/3alleg.md)
