Thursday, 11 August 2016

Length of the string without using library function

Length of the string without using library function

#include<stdio.h>
main()
{
                char s[20];
                int i = 0 ;
                printf("\n Enter a string: ");
                gets(s);

                while(s[i] != '\0')
                {
                                i++;
                }
                printf("\n Length of string: %d", i );
}
Output:
 Enter a string: Hello Hii
 Length of string: 9

No comments:

Post a Comment