how to resolve this problem

N

niuzb

here is the question:read in a input file such like input.txt,recognise
the english words.output
a list of the words by alphabet and the count of the each word into a
file such like output.txt
e.g.the input.txt is:

Hello world.
Hello every one.
Let us go.
and the output.txt is:
every,1
go,1
hello,2
let,1
one,1
us,1
world,1
I remember some book has the answer ,but i can't remember the name of
the book

regardly
 
R

rrs.matrix

u can start off with this code..
mind u it has a some bugs, but it can get u started..
the program will repeat the search for words that have been searched;
also it does not consider the '.' after at the end of a line.
u will have to finish it up.

#include<stdio.h>
FILE *rptr;

int main()
{
int wcount=0;
char str1[50],str2[50];
long cpos;

rptr=fopen("input.txt","r");
fscanf(rptr,"%s",str1);
while(!feof(rptr))
{
cpos=ftell(rptr);
wcount=1;
str2[0]='\0';
while(!feof(rptr))
{
fscanf(rptr,"%s",str2);
if(strcmp(str1,str2)==0) wcount++;
}
printf("\n%s:%d",str1,wcount);
fseek(rptr,cpos,SEEK_SET);
fscanf(rptr,"%s",str1);
}


return 0;
}
 
C

CBFalconer

niuzb said:
here is the question:read in a input file such like input.txt,
recognise the english words.output a list of the words by alphabet
and the count of the each word into a file such like output.txt
e.g.the input.txt is:

Hello world.
Hello every one.
Let us go.
and the output.txt is:
every,1
go,1
hello,2
let,1
one,1
us,1
world,1
I remember some book has the answer ,but i can't remember the name of
the book

wdfreq, which is one of the demos for hashlib, available at:

<http://cbfalconer.home.att.net/download/hashlib.zip>

produces:

[1] c:\c\hashlib>wdfreq
Usage: wdfreq < inputfile > outputfile
collects all words in inputfile and outputs a
sorted (by frequency) list of words and the
frequency of their occurences, ignores case.

Signal EOF to terminate (^D or ^Z usually)
hello world
hello every one
let us go
^Z
8 words, 7 entries, 10 probes, 2 misses
2 hello
1 every
1 go
1 let
1 one
1 us
1 world

Read the following URLs and sig before replying or otherwise
posting again. Remember, google is not usenet, only a poor
interface to it.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
B

Barry

CBFalconer said:
niuzb said:
here is the question:read in a input file such like input.txt,
recognise the english words.output a list of the words by alphabet
and the count of the each word into a file such like output.txt
e.g.the input.txt is:

Hello world.
Hello every one.
Let us go.
and the output.txt is:
every,1
go,1
hello,2
let,1
one,1
us,1
world,1
I remember some book has the answer ,but i can't remember the name of
the book

wdfreq, which is one of the demos for hashlib, available at:

<http://cbfalconer.home.att.net/download/hashlib.zip>

produces:

[1] c:\c\hashlib>wdfreq
Usage: wdfreq < inputfile > outputfile
collects all words in inputfile and outputs a
sorted (by frequency) list of words and the
frequency of their occurences, ignores case.

Signal EOF to terminate (^D or ^Z usually)
hello world
hello every one
let us go
^Z
8 words, 7 entries, 10 probes, 2 misses
2 hello
1 every
1 go
1 let
1 one
1 us
1 world

Read the following URLs and sig before replying or otherwise
posting again. Remember, google is not usenet, only a poor
interface to it.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>

We could see this response coming from a mile away :).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top