Search This Blog

Translate

c program example to find largest word in a string


c program example to find largest word in a string

#include
#include
void main()
{
   char  str[1000];
   int   length,i,start=0,end=0,j;
   int   finalStart, finalEnd , count = 0;
   printf("Enter the First String :\n");
   gets(str);

   length = strlen(str);
   for(i=0;i
   {
            j=i;
            start=i;
            while(str[j]!=' ' && str[j]!='\0' )
            {
                end = j;
                j++;
            }
            i=j;
            if(count < end - start )
            {
                count = end - start;
                finalStart = start;
                finalEnd = end;
            }

   }
   printf("\nLongest Word : ");
   for(i=finalStart; i<=finalEnd ; i++ )
   printf("%c",str[i]);
   return 0;
}

C Program example List

Google+ Badge