Skip to content

String splitter for c language just like split methods given by default by the majority of OOP languages.

Notifications You must be signed in to change notification settings

Virgula0/c-string-splitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Instead with this function, the passed string will not be manipulated.

Usage

Include splitter.h in your code.

#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

img

About

String splitter for c language just like split methods given by default by the majority of OOP languages.

Topics

Resources

Stars

Watchers

Forks