Strlen() finds the length of a string - C String

C examples for String:String Function

Description

Strlen() finds the length of a string

Demo Code

#include <stdio.h> 
#include <string.h> /* contains string function prototypes */ 

void fit(char *, unsigned int); 
 
int main(void) { 
    char mesg[] = "Things should be as simple as possible," 
    " but not simpler."; 
 
    puts(mesg); /*  w w w  .j ava2 s.c om*/
    fit(mesg,38); 
    puts(mesg); 
    puts("this is a test."); 
    puts(mesg + 39); 
 
    return 0; 
} 
 
void fit(char *string, unsigned int size) 
{ 
    if (strlen(string) > size) 
        string[size] = '\0'; 
}

Result


Related Tutorials