Split a string into an array with ease ― in C
Report Bug
·
Request Feature
- Clone the repo
> git clone https://github.com/Mantra-Coding/strsplit
- Move
strsplit.c
andstrsplit.h
into your project folder
strsplit's signature is
char** strsplit(char* string, char delimiter, int* length);
Where char* string
is the string you want to split, char delimiter
is the delimiter to separate strings and int* length
is a pointer which will be the length of the resulting array.
// Example: split a const string passed as parameter
#include "strsplit.h"
int main() {
int words;
char** split = strsplit("split this string into an array of strings", ' ', &words);
for (int i = 0; i < words; i++) {
printf("%s\n", split[i]);
}
/* Output:
split
this
string
into
an
array
of
strings
*/
}
- Edge cases
- Handling of first position and-or last position delimiters in the input string.
- Support escape characters
- Handling consecutive double delimiters
- Add Header File
- Optimize performance (aka 👋 realloc)
- Error handling
- Add license
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (git checkout -b feature/AmazingFeature)
- Commit your Changes (git commit -m 'Add some AmazingFeature')
- Push to the Branch (git push origin feature/AmazingFeature)
- Open a Pull Reques
Distributed under the MIT License. See LICENSE
for more information.