Search
 
SCRIPT & CODE EXAMPLE
 

C

delimter in c

/*
a delimter function, that returns an array of strings dynamically allocated
and splitted according to one char 
*/
char** split(const char* str, char delimiter){

    char** arr = NULL;
    const char* p;

    if(str == NULL)
        return NULL;

    unsigned int arrsize = 0;

    for(p=str; *p; p++) {

        if(*p == delimiter) {

            arr = (char**)realloc(arr, sizeof(char*)*(++arrsize));
            arr[arrsize-1] = (char*)calloc(sizeof(char), (p-str)+1);
            strncpy(arr[arrsize-1], str, p-str);
            str = p+1;

        }

    }

    // Last item
    arr = (char**)realloc(arr, sizeof(char*)*(++arrsize));
    arr[arrsize-1] = (char*)calloc(sizeof(char), (p-str)+1);
    strncpy(arr[arrsize-1], str, p-str);
    return arr;
}
Comment

PREVIOUS NEXT
Code Example
C :: how to link flexslider 
C :: send an array through a pipe 
C :: uninstall elgg from hostgtor 
C :: epita 
C :: how to make C program blink on screen 
C :: c timespec 
C :: extended euclidean algorithm to find x and y 
C :: code to reverse the words in a sentnce 
C :: buble sort in c that ask user input 
C :: arcolinux 
C :: djb2 algorithm for C 
C :: assembly lea instruction 
C :: gnuplot rectangle border color 
C :: WARNING: QA Issue: rdepends on 
C :: How to set bit in float number in C 
C :: deepak rake 
C :: Print fabionci with fork in C 
C :: unity read text file line by line 
C :: listas enlazadas/ linked lists 
C :: class to const void * 
C :: gcc comand for running hello.c 
C :: how to write a hello world program in c 
C :: c local variable 
Dart :: list item bottom border in flutter 
Dart :: flutter clear navigation stack 
Dart :: if directory exists flutter 
Dart :: how to print in the same line in dart 
Dart :: Flutter - BoxShadow Widget 
Dart :: flutter linear progress indicator height 
Dart :: how to disable screen rotation in flutter 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =