Table of Contents
show
strlen()
Find length of string
temp_variable = strlen(string_name);
Program: compute string Length using string function
#include<stdio.h>
#include<string.h>
int main()
{
char s[100];
int length;
puts("Enter string");
gets(s);
length = strlen(s);
printf("Length = %d",length);
return 0;
}
Output
Enter string
computer
Length = 8
Program: Compute String Length without using library function
#include<stdio.h>
int main()
{
char s[100];
int i;
puts("Enter string");
gets(s);
while(s[i] != '\0')
{
i++;
}
printf("Length = %d",i);
return 0;
}
Output
Enter string
computer
Length = 8
Views: 1