C Program to determine string length

Simple C program to find length of string: In C language, char array is called by string and at the end of string, there is null character. Null character is denoted by '\0'. So here is a C program to determine length of string using null character.
#include<stdio.h>
int main()
{
 char str[]="C Basic Examples";
 int i=0,len=0;
 while(str[i]!='\0')
 {
 len++;
 i++; 
 }
 printf("Length of string : %d\n",len);
 return 0;
}

Another C program using strlen() function
To use strlen() function, we add "string.h" library.
#include<stdio.h>
#include<string.h>
int main()
{
 char s[]="C Basic Example";
 int len=0;
 len=strlen(s);
 printf("Length of string : %d\n",len);
 return 0;
}




Popular posts from this blog