C program to find the length of a given string
kw.c
#include <stdio.h>
#include <string.h>
int main()
{
    char s[50];
    printf("———————————————————————————————————————————");
    printf("\nProgram to print length of a given string");
    printf("\n———————————————————————————————————————————");
    printf("\nEnter the string ");
    scanf("%s", s);
    int l = strlen(s);
    printf("\nLength of string is %d", l);
    printf("\n———————————————————————————————————————————\n");
    return 0;
}
Output
kodingwindow@kw:~$ gcc kw.c
kodingwindow@kw:~$ ./a.out ——————————————————————————————————————————— Program to print length of a given string ——————————————————————————————————————————— Enter the string KODINGWINDOW Length of string is 12 ——————————————————————————————————————————— kodingwindow@kw:~$
Advertisement