Oct 3, 2011

C Program to implement strlen function

Write a c program to find the length of a string without using the built-in function strlen(). Program will calculate the length of the string using for loop by going through each character of the string, till its end. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                      Happy Coding
***********************************************************/
#include <stdio.h>

void main()
{
 char string[50];
 int  i, length = 0;

 printf("Enter a string\n");
 gets(string);

 for (i=0; string[i] != '\0'; i++) /*keep going through each */
 {                                 /*character of the string */
  length++;                     /*till its end */
 }
 printf("The length of a string is the number of characters in it\n");
 printf("So, the length of %s =%d\n", string, length);
}
Read more Similar C Programs
Searching in C

C Strings

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!