https://github.com/sunjay/dsarray
A dynamically-sized array in C (work in progress)
https://github.com/sunjay/dsarray
Last synced: about 1 year ago
JSON representation
A dynamically-sized array in C (work in progress)
- Host: GitHub
- URL: https://github.com/sunjay/dsarray
- Owner: sunjay
- License: mpl-2.0
- Created: 2021-03-15T04:51:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-04-23T19:20:15.000Z (about 4 years ago)
- Last Synced: 2024-12-25T17:09:54.288Z (over 1 year ago)
- Language: C
- Size: 64.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dsarray - Dynamically-sized Array in C
[](https://github.com/sunjay/dsarray/actions/workflows/dsarray.yml)
This is an implementation of a dynamically sized array in C. It uses `void *` to simulate
"polymorphism" so you do not need to redefine the array every time you need to use it for a
different type. To make this work, you need to pass in the size of the type you are storing when
you create the array.
```c
dsarray items;
dsarray_init(&items, sizeof(int));
// Push an item into the array
int value = 3;
dsarray_push(&items, &value);
// Get the item from the array and print it
int *item = dsarray_get(&items, 0);
printf("%d\n", *item);
```
## Building
Run `make` from the project's root directory.
This will generate `build/libdsarray.a` and `build/libdsarray.so`.
## Running Tests
Run `make test` from the project's root directory.
This will run the unit tests in the `tests` directory.