C Program to Find Biggest and Smallest word from a String

C Program to Find Biggest and Smallest word from a String . Compiled in Dev C++

#include<stdio.h>
#include<string.h>
#include<conio.h>
#include <ctype.h>
void copyData(char *,char *);
void findSamallestAndBigestWord(char *,char [],char []);
main()
{
       char text[50],big[50],small[50];
       int position,start;
      
       printf("\nProgram to Find Biggest and Smallest word from a String \n");
       printf("\n------------------------------------------------------------------\n\n\n");
       printf("Enter Text : ");                                                   
       gets(text);    
       
       findSamallestAndBigestWord(text,big,small);
       
       printf("\n\nBiggest Word is : %s" ,big);
        
       printf("\n\nSmallest Word id : %s" ,small);
        
    
       getch();
       
}
       
       
                                 
 void findSamallestAndBigestWord(char a[],char MAX[],char MIN[])
  {
      char *p,tempMAX[30],tempMIN[30];
      int i,max=0,min,pos=0;
      if(isspace(a[strlen(a)-1]))
      {}
      else{
      a[strlen(a)]=' ';
      a[strlen(a)]='\0';
      }
      min=strlen(a);
      for(i=0;i<strlen(a);i++)
      {
            p=&a[i];
           
            if(*p!=' ')
            {
                   tempMAX[pos]=*p; 
                   tempMIN[pos]=*p;
                   pos++;
                          
            }
             else{
                 
            tempMAX[pos]='\0';
            tempMIN[pos]='\0';
            
            
            if(strlen(tempMAX)>max)
            {
                copyData(tempMAX,MAX); 
                max=strlen(tempMAX);              
            }
            if(strlen(tempMIN)<min)
            {
                copyData(tempMIN,MIN);
                min=strlen(tempMIN);                      
            }
            
             pos=0;
            
            }
            
             
      }
            
                    
  }
  
  
  void copyData(char *source,char *target)
  {
       while(*source!='\0')
       {
          *target=*source;
          *source++;
          *target++;
       }
       
      *target='\0';
      
  }   

Output

biggest

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s