Ad Code

Responsive Advertisement

How to find Largest Word in a String.

How to find Largest Word in a String.

Here we are going to find the Largest Word In a String. The Largest Word are find into a String using C language.


Steps  To find Largest Word in a String.


  1. First we create a char array[] To store entire words of a String.
  2. Second we create a Structure to Store all the words of a string
  3. Then we use the for loop to start from [0] index to ['\0'] NULL index of a String.
  4. and we used a if condition to divide all the word of a string.
  5. and we use an integer veriable to store the first length word of a String
  6. And then we compare all the length of a String word to te length(Integer) veriable And which length is largest then the other String word this is called Largest Word of a String.


The Output Of programTo find Largest Word in a String



Input : "This is a test string"
Output : Maximum length word: string

Input : "codewithvibhu A computer Science portal" 
Output : Maximum length word: codewithvibhu



how to find Largest Word in a String















#include<stdio.h>
#include<string.h>
struct highest
{
 char name[10];
}obj[10];    // Create Structure objrct

void main(){ 
 char na[20];
 int j=0,k=0,len=0;
 printf("Enter a String :");
 scanf(" %[^\n]s",na);
 for(int i=0; i<strlen(na); i++){
  if(na[i]==' '){
   j++;         //  Here, we are check the condition 
   k=0;         //  and find all the word
  }
  else{         
   obj[j].name[k]=na[i];    
   k++;
  }
 }
 len=strlen(obj[0].name);
 for(int i=0; i<=j; i++){
  if(len<strlen(obj[i].name)){
   len=strlen(obj[i].name);  // find Highest length
  }
 }
 for(int i=0; i<=j; i++){
  if(len==strlen(obj[i].name)){  /* Check the len is equal to the Structure object*/
   printf("Highest length is %s\n",obj[i].name);
  }
 }
}




out put :
 

Enter a String :my name is vibhu
Highest length is vibhu

How to find Largest Word in a String in C .

Download the programs file:

👉 Click Here To Download the File ðŸ‘ˆ


If you like code with vibhu  and would like to contribute, skillshop. you can also write an article using exceedlms.   This link :

https://docs.google.com/forms/d/e/1FAIpQLScAmvlPvNUz35R-G0nc_zpRVP3o8xlhtFgC3aKPyLetX_RyXg/viewform?pli=1


OR  mail your article to codewithvibhu@gmail.com.  See your article appearing on the  com/student code with vibhu main page and help other /award/ students. 

And also Like and comment our program👇.

Post a Comment

1 Comments