TAAFT
Free mode
100% free
Freemium
Free Trial
Deals

BaseMax / my-c-array

Dynamic array implementation in C with a modular, folder-based structure.

0 0 Language: C License: MIT Updated: 10mo ago

README

my-c-array

Dynamic array implementation in C with a modular, folder-based structure.

๐Ÿ”ง Features

  • ๐Ÿงฉ Modular Operations: Efficient functions for array append, prepend, resize, delete, and access.
  • ๐Ÿ› ๏ธ Custom Memory Management: Define custom free functions for array element deallocation.
  • ๐Ÿ”“ Expandable: Easily extendable with additional array-related functions.
  • ๐ŸŒ Cross-Platform: Build scripts for both Linux (bash or make) and Windows (batch).
  • ๐Ÿ“‚ Organized Structure: Each module is in its own directory for easy maintenance.
  • ๐Ÿ“š Static Library: Compiles into libmyarray.a for easy reuse in other projects.
  • โš™๏ธ C Standard: Written in pure C for maximum compatibility.
  • ๐Ÿš€ Easy to Build: Simple setup for compiling and integrating into other projects.

๐Ÿ—‚๏ธ Suggested Directory Layout

my-c-array/
โ”œโ”€โ”€ Makefile
โ”œโ”€โ”€ build.sh
โ”œโ”€โ”€ build.bat
โ”œโ”€โ”€ libmyarray.a  (after build)
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ array_append/
โ”‚   โ”‚   โ”œโ”€โ”€ array_append.c
โ”‚   โ”‚   โ””โ”€โ”€ array_append.h
โ”‚   โ””โ”€โ”€ ...

๐Ÿ› ๏ธ Build Instructions

Linux / macOS

chmod +x build.sh
./build.sh

Or using make:

make

Windows

build.bat

This will compile the source files under src/, place the object files in build/, and generate a static library libmyarray.a or an executable if you add a main.c.

๐Ÿ“ฆ Functions

  • Modular directory layout
  • Cross-platform build scripts (.sh and .bat)
  • Basic operations like:
    • array_create
    • array_append
    • array_delete
    • array_get
    • array_resize
    • array_prepend
    • array_size

๐Ÿ“„ Example Header

Hereโ€™s what the base array type looks like:

#ifndef _ARRAY_TYPE_H_
#define _ARRAY_TYPE_H_

#include <stddef.h>  // for size_t

typedef void (*array_free_func_t)(void*);

typedef struct {
    void** items;              // actual data
    size_t capacity;           // total capacity
    size_t size;               // current number of elements
    array_free_func_t freer;   // custom free function (NULL means no-op)
} array_t;

#endif

๐Ÿ“œ License

MIT License
ยฉ 2025 Max Base

0 AIs selected
Clear selection
#
Name
Task