Create your own function to get the length of a string - C String

C examples for String:String Function

Description

Create your own function to get the length of a string

Demo Code

#include <stdio.h>

/* return length of s */
int strlen(char s[]){
    int i = 0;/*  w ww . jav a  2s  .co m*/
    while (s[i] != '\0')
        ++i;
    return i;
}

int main(){
    char buf[1000];

    while (fgets(buf, sizeof buf, stdin) != NULL)
        printf("%d%s", strlen(buf), buf);
    return 0;
}

Result


Related Tutorials