programming-examples/c/String/C Program to Find the Length of a String without using the Built-in Function.c
2019-11-15 12:59:38 +01:00

27 lines
666 B
C

/*
* C program to find the length of a string without using the
* built-in function
*/
#include <stdio.h>
void main()
{
char string[50];
int i, length = 0;
printf("Enter a string \n");
gets(string);
/* keep going through each character of the string till its end */
for (i = 0; string[i] != '\0'; i++)
{
length++;
}
printf("The length of a string is the number of characters in it \n");
printf("So, the length of %s = %d\n", string, length);
}
/*
*OUTPUT:
Enter a string
Sanfoundry
The length of a string is the number of characters in it
So, the length of Sanfoundry = 10
*/