answersLogoWhite

0


Best Answer

#include<stdio.h>

main()

{

int i,words,spaces;

char a[30];

printf("enter the string") ;

scanf("%s",a);

for(i=0;a[0]!="\0";i++)

{

if (a[i]=' ')

spaces++;

}

printf("the no. of spaces in the string is %d",spaces);

printf("the number of words in the string is %d",spaces+1);

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

how to find the frequency of words in a sentence?

//program to find occurence of a word in a sentence

import java.io.*;

public class cnt2

{

public static void main(String args[])throws IOException

{

int times=0,count=0,x=0,no=0;

InputStreamReader ir=new InputStreamReader(System.in);

BufferedReader br=new BufferedReader(ir);

String s,w;

System.out.println("Enter the sentence:");

s=br.readLine();

System.out.println("Enter the word:");

w=br.readLine();

try{

for(int i=0;i<s.length();i++)

{

if(w.charAt(0)==s.charAt(i))

{

for(int j=0;j<w.length();j++,i++)

{

if(s.charAt(i)==w.charAt(j))

{ count=count+1;}

if(count==w.length())

{no=no+1;count=0;};

}

}

}

catch(Exception e){}

if(no==0)

{

System.out.println("word is not present");

}

else

{

System.out.println("word is present "+no+" times");

}

}

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

#include<iostream.h>

#include<conio.h>

#include<string.h>

char temp[30][30];

int check(char x[],int n)

{

for(int i=0;i<n;i++)

{

if(strcmp(temp[i],x)==0)

return 0;

}

return 1;

}

void main()

{

char a[100],b[20],ch,c[10][10];

int i=0,j,n=0,k=0,count,m;

clrscr();

cout<<"\n Enter any string and end with $::";

cin.get(ch);

do

{

a[n]=ch;

n++;

cin.get(ch);

}while(ch!='$');

a[n]='\0';

for(;;)

{

for(j=0;(a[i]!=' ')&&(a[i]!='\0');j++)

{

b[j]=a[i];

i++;

}

b[j]='\0';

strcpy(c[k],b);

k++;

if(a[i]==0)

break;

i++;

}

cout<<"\n\n------------------------------------\n";

cout<<"\n\tword\tFrequency\n";

cout<<"\n\n------------------------------------\n";

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

{

count=1;

m=check(c[i],i);

for(j=i+1;j<k;j++)

{

if(strcmp(c[i],c[j])==0 && m==1)

count++;

}

if(m==1)

{

strcpy(temp[i],c[i]);

cout<<"\t"<<c[i]<<"\t"<<count<<endl;

}

}

cout<<"\n\n------------------------------------\n";

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

to read and write occurence of a particular character

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C program to read a text and count occurrence of a particular word?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Explain how to check the ratios of a gearbox?

The input and output shafts need to be marked Then put in a particular gear Rotate the input shaft ten revolutions and count the output shaft revolutions. Or read the specs in the manual OR disassemble the trans and count the gear teeth.


What is the word count in the book Beezus and Ramona?

I read the book the word count is about 450


How do i read Aerobic plate count?

get a tutor


How do you flash the tbi computer on a 91 camaro?

You can not. If you are experiencing a particular problem you can check TSB's for an updated PROM. That is Program Read Only Memory. It would have to purchased through the dealer.


How many syllables has read?

it only has one stupid idiot.. can't you read or count??


Where can one read about the Apollo space program?

There are a number of websites that allow one to read about the Apollo space program. Wikipedia has many details about the program and each of the missions.


What is the responsibility of TV news reader?

to read the particular news of a particular day


How can you read a directory in a C program?

no


What program do you use to read txt file?

A .txt can be read with notepad.


What is the Read 180 program meant to accomplish?

The Read 180 program is a reading program to improve the reading and writing skills of students in grades 4 through 12. The program uses software and an iPad to accomplish this.


What does a high count of alt in blood mean in catalyst dx test?

The ALT and AST give a read on a blood test together. These two numbers have a ratio together. There is no particular meaning of just the ALT on it's own.


How do you count syllables?

read it aloud and put your hand underneath it and count how many movements you do while saying a word