Program to calculate Length of String


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

            char line[40] ;
            int calculate_length ( ) ;
            void main ()
    {
      int  length ;
      cout <<" Enter a string : " ;
      gets(line) ;
      length = calculate_length ( ) ;
      cout<<" \nThe string length is "<<length ;
      getch ( ) ;
    }

    int calculate_length ( )
    {
      int count = 0 ;
      while (line[count] != '\0')
        count++ ;
    return (count) ;
}

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|