Saturday 15 September 2012

String011

Input a sentence and print the number of word in it.

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

void main ( )
{
           char      nm[80];
           int         i, ln, co = 0;
           clrscr ( );
                    
           printf("\n\n\n\t\t Enter a sentence....:"); gets (nm);
           for ( ln = 0; nm[ln] != '\0'; ln++ );
                
           for ( i = 0; i < ln; i++ )
           {                           
                       if ( nm[i] == ' ' )
                       {                       
                                       co++;
                       }
           }   
          
           printf("\n\n\n\t\t Number of sentence...: %d ", co + 1);
           getch ( );
}
Click here to contact us

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...