C Programming Tutorial

Advertisements

Write C++ program to count the length of a string



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

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

              cout<<"\nEnter any string : ";
              gets(str);
              
              for(i=0;str[i];i++)
                     len++;
              
              cout<<"\nLength of String : "<<len;

              getch();
    }

   Output : 

              Enter any string : My name is Kumar
              Total blank spaces : 16




Advertisement