https://github.com/virgula0/c-string-splitter
String splitter for c language just like split methods given by default by the majority of OOP languages.
https://github.com/virgula0/c-string-splitter
c library linux osx split split-methods string-splitter strings utility
Last synced: 3 months ago
JSON representation
String splitter for c language just like split methods given by default by the majority of OOP languages.
- Host: GitHub
- URL: https://github.com/virgula0/c-string-splitter
- Owner: Virgula0
- Created: 2020-08-29T19:08:11.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-10-17T13:30:05.000Z (over 5 years ago)
- Last Synced: 2025-03-06T09:46:49.148Z (over 1 year ago)
- Topics: c, library, linux, osx, split, split-methods, string-splitter, strings, utility
- Language: C
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# c-string-splitter
String splitter for c language just like split methods given by default by the majority of OOP languages.
Since i never found an easy implemantion and already well-coded function for split strings in c i build my own version.
This script avoid the use of functions like ```strtok``` wich modifies the original passed string to the function. Example of some problems when using strtok: [StackOverflow](https://stackoverflow.com/questions/63151324/segmentation-fault-returned-using-strtok/63151617).
Instead with this function, the passed string will not be manipulated.
# Usage
Include ```splitter.h``` in your code.
```c
#include "splitter.h"
int main(){
char *string = "this|is|a|long|string|which|needs|to|be|splitted\n";
char ** strings = split(string,'|');
int count = 0;
printf("\nOriginal one: %s",string);
printf("Splitted:");
while (*strings){
printf(" %s",*strings++);
count++;
}
printf("Original one not touched: %s\n",string);
//remember to deallocate once finished
if (strings){
strings -= count;
free(strings);
}
}
```
# MakeExample
Compile the example given with:
```
make
./main
```
