Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Write a program to print distinct words in an input
along with their count in input in decreasing order of their
count..



Write a program to print distinct words in an input along with their count in input in decreasing o..

Answer / gururaj l j

Solution

/* This Program counts the distinct words in the input
string preceded each word by its count */


#include <stdio.h>
#include <string.h>

void DistinctWords(char s[ ]);


void main()
{
char s[100];

printf("Enter the String ");
gets(s);

if(strlen(s) <= 0)
printf("Please provide the input
string\n");
else
DistinctWords(s);
}

/* Purpose: This function counts the distinct words in the
input string preceded each word by its count
Input : String
Output : distinct words with its count
*/

void DistinctWords(char s[])
{
char words[50][50];
char distinct[50];
int i, j, l, k = 0, start, end, f = 1, m = 0, n =
0;
int count;
int countindex[20],cindex = 0;


for(l = 0,i = 0; s[i] != ' '; i++, l++)
words[k][i] = s[i];

words[k][i] = '\0';
k++;
start = i+1;


for(i = i+1; s[i]; i++)
{
if(s[i] == ' ')
{
end = i-1;
f = i+1;

for(j = 0, l = start; l <= end;
l++, j++)
words[k][j] = s[l];


words[k][j] = '\0';

k++;
start = i+1;
}
}


for(l = f, i = 0; s[l]; i++, l++)
words[k][i] = s[l];

words[k][i] = '\0';


for(i = 0;i <= k; i++)
{
count = 0;

for(j = i; j <= k; j++)
{
if((stricmp(words[i], words[j])) == 0)

count++;
}

f = 1;

for(j = 0; j < i; j++)
{
if(strcmp(words[i], words[j]) == 0)
{
f = 0;
break;
}
}


if(f == 1)
printf("\n\t%s Occur %d Times\n", words[i],
count);
}
}

Is This Answer Correct ?    18 Yes 7 No

Post New Answer

More C Interview Questions

What is data types?

0 Answers  


how can i get output the following... 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 and 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 plz plz...

3 Answers  


Is boolean a datatype in c?

0 Answers  


What are the types of type qualifiers in c?

0 Answers  


What is the difference between a string and an array?

0 Answers  


In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none

0 Answers  


how to use enum datatype?Please explain me?

3 Answers   Excel,


What is the difference between formatted&unformatted i/o functions?

0 Answers  


What is the purpose of Scanf Print, getchar, putchar, function?

3 Answers  


Write an interactive c program that will encode or decode a line of text. To encode a line of text, proceed as follows: Convert each character, including blank spaces, to its ASCII equivalent. Generate a positive random integer. Add this integer to the ASCII equivalent of each character. The same random integer will be used for the entire line of text. Suppose that N1 represents the lowest permissible value in the ASCII code, and N2 represents the highest permissible value. If the number obtained in step 2 above exceeds N2, then subtract the largest possible multiple of N2 from this number, and add the remainder to N1. Hence the encoded number will always fall between N1 and N2, and will therefore always represent some ASCII character. Display the characters that correspond to the encoded ASCII values. The procedure is reversed when decoding a line of text. Be certain, however, that the same random number is used in decoding as was used in encoding.

1 Answers   Amazon, CSJM, HCL, Microsoft, TCS, Wipro,


What is the purpose of the code, and is there any problem with it? unsigned int f( unsigned n ) { return –n & 7; }

1 Answers   Google,


Why is malloc used?

1 Answers  


Categories