CPP Program To Find The Length Of The String

A simple Program to find the length of the string without using the predefined string function. This will not count the null character.

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int i,len=0;
char str[10];

cout << "enter the string" << endl;
cin >>str;

for(i=0;str[i]!=NULL;i++)
{
len++;
}
cout << len << endl;
getch();
}

Output:
enter the string
tanmay
6

 

Leave a Reply