← 返回首页
GitHub - farukalpay/DynamicArray: This library implements a std::vector like Dynamic Array data structure in C, allowing for the creation, modification, and manipulation of an array whose size can be dynamically adjusted during runtime. · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

farukalpay/DynamicArray

Go to file
Code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
View all files

Repository files navigation

More items

📝 Documentation

Documentation can be found on the following link

⚙️ Introduction

This library implements a std::vector like Dynamic Array data structure in C, allowing for the creation, modification, and manipulation of an array whose size can be dynamically adjusted during runtime. Dynamic array is similar to the standard array in C, but it can grow or shrink in size as needed.

⚒️ Getting Started

Download the repository and copy the library your local project folder (say, ./myproject)

git clone https://github.com/farukalpay/DynamicArray.git cp DynamicArray.h ./myproject

Import DynamicArray.h and get started

#include DynamicArray.h
Example usage is shown below
#include <stdio.h> #include "DynamicArray.h" // Structure for a person typedef struct { char name[50]; int age; } Person; int main() { DynamicArray personArray; initDynamicArray(&personArray, sizeof(Person)); // Create some Person objects Person person1 = { "Alice", 25 }; Person person2 = { "Bob", 30 }; Person person3 = { "Charlie", 35 }; // Push the Person objects into the DynamicArray pushBack(&personArray, &person1); pushBack(&personArray, &person2); pushBack(&personArray, &person3); // Get and print the elements in the DynamicArray printf("-- Elements Before Update --\n"); size_t numPersons = personArray.size; for (size_t i = 0; i < numPersons; i++) { Person* person = (Person*)getElementAt(&personArray, i); printf("Name: %s, Age: %d\n", person->name, person->age); } // Pop an element from the back of the DynamicArray popBack(&personArray); // Resize the DynamicArray resize(&personArray, 2); // Create a new DynamicArray DynamicArray newPersonArray; initDynamicArray(&newPersonArray, sizeof(Person)); // Create another Person object Person person4 = { "David", 40 }; // Push the Person object into the new DynamicArray pushBack(&newPersonArray, &person4); // Concatenate the new DynamicArray with the original DynamicArray concatenate(&personArray, &newPersonArray); // Get and print the updated elements in the DynamicArray printf("-- Elements After Update --\n"); numPersons = personArray.size; for (size_t i = 0; i < numPersons; i++) { Person* person = (Person*)getElementAt(&personArray, i); printf("Name: %s, Age: %d\n", person->name, person->age); } // Clear the DynamicArray clearDynamicArray(&personArray); return 0; }
Output is shown below
-- Elements Before Update -- Name: Alice, Age: 25 Name: Bob, Age: 30 Name: Charlie, Age: 35 -- Elements After Update -- Name: Alice, Age: 25 Name: Bob, Age: 30 Name: David, Age: 40

🆘 Support

If you find any errors, mistakes please feel free to submit a pull request. If you would like to reach me, you can send me an e-mail via faruk.1alpayu@gmail.com ​

About

This library implements a std::vector like Dynamic Array data structure in C, allowing for the creation, modification, and manipulation of an array whose size can be dynamically adjusted during runtime.

Topics

Resources

License

Stars

9 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

Footer

© 2026 GitHub, Inc.