Skip to content

Mantra-Coding/strsplit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub contributors GitHub issues GitHub

strsplit

Split a string into an array with ease ― in C
Report Bug · Request Feature

Table of Contents

Installation

  1. Clone the repo
> git clone https://github.com/Mantra-Coding/strsplit
  1. Move strsplit.c and strsplit.h into your project folder

Usage

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
	*/
}

TODO

  • 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

Contributing

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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Reques

License

Distributed under the MIT License. See LICENSE for more information.

About

Split a string into an array with ease ― in C

Resources

License

Code of conduct

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages