Counting the Characters in a String with your own function - C Function

C examples for Function:Utility Function

Description

Counting the Characters in a String with your own function

Demo Code

#include <stdio.h>

int stringLength (const char string[]){
    int count = 0;

    while ( string[count] != '\0' )
        ++count;/*from  www  .  ja v  a2s  .  c o m*/

    return count;
}

int main (void)
{
    char word1[] = {'a', 'b', 'd', 'e', 'r', '\0'};
    char word2[] = {'a', 'b', '\0'};
    char word3[] = {'a', 'b', 'c', '\0'};

    printf("%i   %i   %i\n", stringLength (word1), stringLength (word2), stringLength (word3));

    return 0;
}

Related Tutorials