Wednesday, 21 January 2015

C Program to find length of a string without using strlen()


This is simple C Program which prints out the length of a string without using the string function strlen().

PROGRAM :
#include <stdio.h>
#include <stdlib.h>

int main()
{
    char name[20];
    int i,length=0;
    printf("Enter any name(String) : \t");
    gets(name);
    for(i=0; name[i]!='\0'; i++)
        length++;
    printf("\nThe length of the string is \t %d \n",i);
    return 0;
}

OUTPUT : 
C Program to find length of a string without using strlen()

No comments:

Post a Comment