Using the strlen() function to get string length - C String

C examples for String:String Function

Description

Using the strlen() function to get string length

Demo Code

#include <stdio.h>
#include <string.h>

int main( void )
{
   size_t length;/*from   w w w  .j a  va2 s . c  om*/
   char buf[80];

    while (1)
    {
        puts("\nEnter a line of text, a blank line to exit.");
        gets_s(buf);

        length = strlen(buf);

        if (length != 0)
            printf("\nThat line is %u characters long.", length);
        else
            break;
    }
     return 0;
}

Result


Related Tutorials