Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

How to get the number of characters in a string without using strlen function

#include <stdio.h> 
int length_of_string(char *s) {
    int count = 0;

    while (s != '') {
        count++;
        p++;
    }

    return (count);
}
/**
 * main - check the code
 *
 * Return: Always 0.
 */
int main(void)
{
    char *str;
    int len;

    str = "My first strlen!";
    len = _strlen(str);
    printf("%d
", len);
    return (0);
}
 
PREVIOUS NEXT
Tagged: #How #number #characters #string #strlen #function
ADD COMMENT
Topic
Name
4+7 =