program to find the second largest word in a paragraph
amongst all words that repeat more thn twice

Answers were Sorted based on User's Feedback



program to find the second largest word in a paragraph amongst all words that repeat more thn twic..

Answer / 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

program to find the second largest word in a paragraph amongst all words that repeat more thn twic..

Answer / pavani

why no body is helping me in this matter

Is This Answer Correct ?    5 Yes 4 No

program to find the second largest word in a paragraph amongst all words that repeat more thn twic..

Answer / marimuthu

By simple

1.find length of each word
2.insert into binary search tree
3.recursively get the left most child of the right sub tree. finally you will get the second largest word.

via this logic you can smallest word,largest word.

is it have criticize?? mail me rainpearls.v@gmail.com

Is This Answer Correct ?    2 Yes 1 No

program to find the second largest word in a paragraph amongst all words that repeat more thn twic..

Answer / sai

lets write a paragraph in an array of strings a[i]
compare that array string
and if exists more than twice in that paragraph strcpy it
with other string b and the next one with string c
if strlen of b<c print b, else c
i got an idea but cant write code
if anyone tries n suceeds/finds fault mail me!
Email ID: smaransaisree@gmail.com

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More C Interview Questions

write a programme to convert temperature from farenheit to celcius?

4 Answers   IBM,


What is an example of enumeration?

1 Answers  


code for bubble sort?

1 Answers  


How variables are declared in c?

0 Answers  


SIR PLS TELL ME THE CODE IN C LANGUAGE TO PRINT THE FOLLOWING SERIES 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1

4 Answers  






How can I do serial ("comm") port I/O?

0 Answers   Celstream,


Can you tell me how to check whether a linked list is circular?

1 Answers  


write a program to reverse a every alternetive words in a string in a place. EX: Input is "this is the line of text" Output should be "shit is eht line fo text" Please any one tell me code for that.

0 Answers   TCS,


Define circular linked list.

0 Answers  


What are unions in c?

0 Answers  


what is the use of keyword volatile??

4 Answers   LG Soft,


WHAT WILL BE OUTPUT OF BELOW CODE . . AND PLEASE EXPLAIN HOW IT COME .. #include<stdio.h> #include<conio.h> void main() { int k=20; printf("%d%d%d%d",k,k++,++k,k); getch(); }

25 Answers  


Categories