program to find the second largest word in a paragraph
amongst all words that repeat more thn twice
Answer Posted / kiran kumar
Hi Pavani,
My name is Kiran.
Iam posting the code for ur Question.
The code is given below.
/* Program to find the second larges word in a paragraph
amongst all words that repeat more than twice */
# include <stdio.h>
# include <stdlib.h>
int main(void)
{
char para[80],*temp1=NULL,*temp=NULL,*first_high,*second_high;
unsigned int first_high_len,second_high_len;
printf("Enter the Paragraph\n");
fgets(para,80,stdin);
temp=strchr((const char*) para, (int)' ');
temp=para;
temp=strchr((const char*)para,(int)' '); /* Assuming
first word as the first highest
word
and storing word and the number of
letters of that word */
first_high_len=temp-para;
first_high=malloc(first_high_len+1);
strncpy(first_high, (const char*) para, first_high_len);
*(first_high+first_high_len)='\0';
temp1=strchr((const char*)temp+1,(int)' '); /* Assuming
second word as the second highest
word
and storing the word and the number of
letters of that word */
second_high_len=temp1-temp-1;
second_high=malloc(second_high_len+1);
strncpy(second_high, (const char*) temp+1, second_high_len);
*(second_high+second_high_len)='\0';
while(1)
{
temp1=strchr((const char*)temp+1,(int)' ');
if(temp1 == NULL)
break;
if(temp1-temp-1 > first_high_len)
{
free(second_high);
second_high=malloc(first_high_len+1);
second_high_len=first_high_len;
strncpy(second_high, (const char*) first_high,
second_high_len);
*(second_high+second_high_len)='\0';
free(first_high);
first_high=malloc(temp1-temp);
first_high_len=temp1-temp-1;
strncpy(first_high, (const char*) temp+1, first_high_len);
*(first_high+first_high_len)='\0';
}
else if(second_high_len < (temp1-temp-1) && first_high_len
!= (temp1-temp-1))
{
free(second_high);
second_high=malloc(temp1-temp);
second_high_len=temp1-temp-1;
strncpy(second_high, (const char*) temp1+1, second_high_len);
*(second_high+second_high_len)='\0';
}
temp=temp1;
}
if(strlen((const char*)temp+1) > first_high_len)
{
free(second_high);
second_high=first_high;
first_high=temp+1;
}
else if(strlen((const char*)temp+1) > second_high_len &&
strlen((const char*)temp+1) != first_high_len)
{
free(second_high);
second_high=temp+1;
}
printf("\nFirst Highest word = %s , Len =
%d",first_high,first_high_len);
printf("\nSecond Highest word = %s , Len = %d",second_high,
second_high_len);
return 0;
}
Check this code if u have any queries please be free
to ask any queries.
Email : kirjony@gmail.com
| Is This Answer Correct ? | 7 Yes | 2 No |
Post New Answer View All Answers
What is variable and explain rules to declare variable in c?
What is the value of a[3] if integer a[] = {5,4,3,2,1}?
Give the rules for variable declaration?
How can you find the day of the week given the date?
What are the application of void data type in c?
Which header file should you include if you are to develop a function which can accept variable number of arguments?
Explain what is the difference between #include and #include 'file' ?
What is the difference between a string and an array?
how to find anagram without using string functions using only loops in c programming
In which language linux is written?
please help me..... please codes and flowchart plz turbo c lang po yan.....please asap response... 3. Make an astrology program. The user types in his or her birthday (month, day, and year as integer), and the program responds with the user’s zodiac sign, horoscope, and other information related to it. If the user’s birth year falls into a leap year, your program should display an appropriate message for it. NOTES: Conditional Statements: it should be with graphics
What is action and transformation in spark?
Hai,I have done with my bachelor of commerce and planing to ms,please suggest me how to convince vo for shifting from commerce to computers. Visa on 8 DEC 2014 Npu university
What is wrong in this statement?
List at least 10 sorting methods indicating their average case complexity, worst case complexity and best case complexity.