Write a program to print distinct words in an input
along with their count in input in decreasing order of their
count..
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 |
in which language c language is written?
What is bin sh c?
program to find the magic square
#include<stdio.h> main() { char s1[]="Ramco"; char s2[]="Systems"; s1=s2; printf("%s",s1); } what will happen if you executed this code?
What does static variable mean in c?
When c language was developed?
print out of string in this format; 1. "rajesh" 2. \n 3. %d
Blade logic interview question. 1st round is a written tests with 15 multiple questions from c and c++. All are simple basic question. Like int main () { Int i=65; Return printf(“%c”, i); } 2nd and 3rd round is technical interview. The position for which I was interview was core UNIX and c. Yes it is for system programming. The company has product name blade server. For their server they are creating their own command for their purpose. Example cd command. We can implement it in a c program by using the chdir() function. So the question asks related to PID, fork, pipe, shared memory, signal. Write a program in c which will act as cp command.
1 Answers BladeLogic, Infosys,
what is the difference between #include<> and #include”…”?
Is it possible to pass an entire structure to functions?
What is the description for syntax errors?
What is the usage of the pointer in c?