Thursday 20 September 2012

String019

 Input a sentence in a string and store first word in another string.

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

void main ( )
{
          char        nm[80], nm1[80];
          int           ln, j, c = 0;
          clrscr ( );
                          
          printf("\n\n\n\t\t Enter a sentence....:"); gets (nm);
          for ( ln = 0; nm[ln] != '\0'; ln++ );
                                            
          for ( j = 0; j < ln; j++ )
          {                                
                       if ( nm[ j] != ' ' )
                       {                                    
                                     nm1[c++] = nm[ j];
                       }                                         
                       else                                         
                       {                                        
                                     break;
                       }
          }
          nm1[c++] = '\0';
                                         
          printf("\n\n\n\t\t WORD....: %s",nm1);
          getch ( );
}
Click here to contact us 

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...