Source Code
// 54.ii. Program to find the length of a string without using library function
// Arpan Das - CST 2nd Year (VOCLET)
#include <stdio.h>
//#include <conio.h>
int strlength(char *);
void main () {
char str[50];
int len;
//clrscr();
printf("\t\t..:: find the length of a string using library function ::..\n\n");
printf("Please enter any string: ");
scanf("%[^\n]%*c", str); // String include space
len = strlength(str);
printf("\nLength of %s is %d", str, len);
//getch();
}
int strlength(char *s) {
int i=0, len=0;
while (s[i++] != '\0') len++;
return len;
}
Output
..:: find the length of a string using library function ::..
Please enter any string: India
Length of India is 5