Sunday 23 September 2012

String027

Input a sentence and find the length of each word of that sentence.

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ( )
{
           char       nm1[80], nm2[80][80];
           int          i = 0, j = 0, c = 0, y = 0, ln;
           clrscr ( );
                                                  
           printf("\n\n\n\t Enter a sentence....:"); gets(nm1);
           ln = strlen (nm1);
                                              
           for ( y = 0; y <= ln; y++ )
           {                                                 
                        if ( nm1[y] != ' ' && nm1[y] != '\0' )
                        {                                                     
                                        nm2[i][ j] = nm1[y];
                                        j++;
                        }                                          
                        else                                                 
                        {                                                     
                                        nm2[i][ j] = '\0';
                                        i++;
                                         j = 0;
                        }
           }             
           printf("\n\n\n\t\t WORD \t LENGTH OF WORD \n\t\t________________________");
           for ( c = 0; c < i; c++ )
           {                                   
                        printf("\n\n\n\t\t %s \t\t %d", nm2[c], strlen (nm2[c]) );
           }
           getch ( );
}
Click here to contact us

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...