Sunday 23 September 2012

String028

Input a sentence and a word, write a program to  find whether the word is in the sentence or not.

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ( )
{
          char       nm1[80], nm2[80][80], nm3[80], nm4[80] ;
          int          i = 0, j = 0, n = 0, y = 0, ln, m = 1;
          clrscr ( );
                                                      
          printf("\n\n\n\t Enter a sentence....:"); gets(nm1);
          printf("\n\n\n\t Enter a word....:"); gets(nm3);
          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;
                       }
          }                
          for ( j = 0; j < i; j++)
          {                                                                                 
                       n = strcmp ( nm2[ j], nm3 );
                       if ( n == 0 )   
                       {                      
                                 m = 0;
                                 break;
                       }
          }                 
          if ( m == 0 )
          {                                  
                       printf("\n\n\n\t\t WORD FOUND!");
          }                                                                 
          else                                                          
          {                                                             
                       printf("\n\n\n\t\t WORD NOT FOUND!");
          }
          getch ( );
}
Click here to contact us

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...