Hi all,
Do anyone know how to write a C program to count the frequency of a
certain key pattern in a given datafile?
Input:
• Three alpha-numeric keys separated by space
• A data file contains M by 3 matrix of alpha-numeric keys. Where M is
number of rows and 3 is number of columns.
Output:
• Number of occurrences of the input keys
Example:
Input file db.txt and its content:
4 7 9
2 1 G
5 3 4
A 3 E
1 A 3
F 5 6
X 0 4
Sample run #1
Please enter 3 keys (separated by space):7 A 4
The key ‘7 ‘ has 1 occurrence in the database
The key ‘A’ has 2 occurrences in the database
The key ‘4’ has 3 occurrences in the database
Sample run #2
Please enter 3 keys (separated by space): A B C
The key ‘A’ has 1 occurrence in the database
The key ‘B’ has zero occurrence in the database
The key ‘C’ has zero occurrence in the database
The following is the hints that I have. However, I do not know how I can
complete the program. Your help will be appreciated.
*************** ************
#include <stdio.h>
#include <string.h>
int numeric[10];
int alpha[26];
void ReadData(char* input_file)
{
FILE* fptr;
char buffer[128];
char* token;
int index;
fptr = fopen(input_fil e, "r");
if (fptr != NULL)
{
while (fgets(buffer, sizeof(buffer), fptr) != NULL)
{
token = strtok(buffer, " ");
while ( token != NULL )
{
if (token[0] >= '0' && token[0] <= '9')
{
/* calculate number of input in numeric[] */
}
else if (token[0] >= 'A' && token[0] <= 'Z')
{
/* calculate number of input in alpha[] */
}
/* Get next token: */
token = strtok( NULL, " " );
}
}
}
}
/* get the occurrence of the specified key */
int GetKeyCount(cha r key)
{
int index;
if (key >= '0' && key <= '9')
{
….. /* return the occurrence of the numeric input key in numeric[] */
}
else if (key >= 'A' && key <= 'Z')
{
….. /* return the occurrence of the alpha input key in alpha[] */
}
else
return 0; /* return 0, if the key is not defined */
}
void main()
{
char enquiry[32]; /* store the enquiry string input by user */
char* token;
ReadData("db.tx t"); /* setup the key occurrence database from the input
file */
printf("Please enter 3 keys (separated by space): ");
while (gets(enquiry) != NULL)
{
token = strtok(enquiry, " "); /* get the key one by one from the line
delimited by a space - e.g. "1 2 A" */
while (token != NULL )
{
/* While there are tokens in "string" */
/* print out the result from the key token[0] and the function
GetKeyCount() */
……..
/* Get next token: */
…….
}
printf("Please enter 3 keys (separated by space): ");
}
} 21 2487
"rccf6178" <rc******@yahoo .com.hk> wrote in message
news:7a******** *************** *******@localho st.talkaboutpro gramming.com... Hi all,
Do anyone know how to write a C program to count the frequency of a certain key pattern in a given datafile?
Make your own homework...
"dandelion" <da*******@mead ow.net> wrote in
news:41******** *************** @dreader9.news. xs4all.nl: Do anyone know how to write a C program to count the frequency of a certain key pattern in a given datafile?
Make your own homework...
^^^^
Do
--
- Mark ->
--
"Mark A. Odell" <od*******@hotm ail.com> wrote in message
news:Xn******** *************** *********@130.1 33.1.4... "dandelion" <da*******@mead ow.net> wrote in news:41******** *************** @dreader9.news. xs4all.nl:
Do anyone know how to write a C program to count the frequency of a certain key pattern in a given datafile? Make your own homework... ^^^^ Do
When your dutch/german/french/latin is as good as mine, it's time to start
correcting me. -- - Mark -> --
"dandelion" <da*******@mead ow.net> wrote: "Mark A. Odell" <od*******@hotm ail.com> wrote in message news:Xn******** *************** *********@130.1 33.1.4... "dandelion" <da*******@mead ow.net> wrote in news:41******** *************** @dreader9.news. xs4all.nl:
Make your own homework... ^^^^ Do
When your dutch/german/french/latin is as good as mine, it's time to start correcting me.
Vind ik best. Het is "_Do_ your own homework", du ungeheurer Idiot,
nicht "Make your own homework". Nunc tace.
Richard
Richard Bos <rl*@hoekstra-uitgeverij.nl> scribbled the following: "dandelion" <da*******@mead ow.net> wrote: "Mark A. Odell" <od*******@hotm ail.com> wrote in message news:Xn******** *************** *********@130.1 33.1.4... > "dandelion" <da*******@mead ow.net> wrote in > news:41******** *************** @dreader9.news. xs4all.nl: > > > Make your own homework... > ^^^^ > Do When your dutch/german/french/latin is as good as mine, it's time to start correcting me.
Vind ik best. Het is "_Do_ your own homework", du ungeheurer Idiot, nicht "Make your own homework". Nunc tace.
Mais Richard, tu as oublie le Français...
--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"The question of copying music from the Internet is like a two-barreled sword."
- Finnish rap artist Ezkimo
"Richard Bos" <rl*@hoekstra-uitgeverij.nl> wrote in message Vind ik best. Het is "_Do_ your own homework", du ungeheurer Idiot, nicht "Make your own homework". Nunc tace.
<plonk>
dandelion <da*******@mead ow.net> scribbled the following: "Richard Bos" <rl*@hoekstra-uitgeverij.nl> wrote in message Vind ik best. Het is "_Do_ your own homework", du ungeheurer Idiot, nicht "Make your own homework". Nunc tace.
<plonk>
<plonk>
--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"A computer program does what you tell it to do, not what you want it to do."
- Anon
"Joona I Palaste" <pa*****@cc.hel sinki.fi> wrote in message
news:cm******** **@oravannahka. helsinki.fi...
<shrug>
"dandelion" <da*******@mead ow.net> wrote in
news:41******** *************** @dreader14.news .xs4all.nl: >> Do anyone know how to write a C program to count the frequency of a >> certain key pattern in a given datafile? > > Make your own homework... ^^^^ Do
When your dutch/german/french/latin is as good as mine, it's time to start correcting me.
When I start writing in any of those languages, I will *welcome* your
corrections. How else will I learn?
--
- Mark ->
-- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Johan Hahn |
last post by:
Wouldn't it be nice if list.count, called without any arguments,
returned a dict with the list's unique items as keys and their
frequency of occurance as values?
>>> .count()
{'a': 1, 1: 2, 2: 1}
>>> 'hello world'.count()
{' ': 1, 'e': 1, 'd': 1, 'h': 1, 'l': 3, 'o': 2, 'r': 1, 'w': 1}
....johahn
|
by: Dung Ping |
last post by:
Such as:
<script>
//code
aaaa
zzzz
ccc
|
by: jwvai316 |
last post by:
I'm having problem in this case. I need to count how many time each
word appears in one sentence. and I need it to be case insensitive
for example when the input is
The quick brown fox jumps over the lazy dog.
and the output is
the 2
|
by: Byomokesh |
last post by:
Dear All,
I have one xml file. I want count cell and divide percentage in between cell (through XSL). Please any one help me.
XML File
-------------
<table border="0" cellspacing="0" cellpadding="1" width="90%">
<thead>
<tr>
|
by: Rahul |
last post by:
Hi,
I tried many option, but did not found solution. Same Validation Error
showing. If I have convert one table, it can easily converted. But If I
have paste another table in same file, then showing validation Error.
This Error is --
=======================================================
| |
by: mpilman |
last post by:
The following oracle query purports to output a word count for all words found in a table column. Is this possible in MYSQL?
Mike
===================================================
Measuring of word frequency in text data SQL query:
select Word, count(*) Frequency
from
(
|
by: writeanand |
last post by:
How can I count the frequency of words in a ASCII File using STL?
I dont know what words will be found in the file ahead of time.
I dont want to use any classes, just a simple program wd do.
Thanks!!!
|
by: not_a_commie |
last post by:
So I have a motherboard with multiple CPU sockets. It seems that if I
create a StopWatch on one thread and then call the Elapsed member from
a different thread that sometimes I get a tick count that's a million
miles away.
My thinking is that I can subclass the StopWatch. Then when the
Elapsed member is called, I can invoke it on the thread...
|
by: waynejr25 |
last post by:
can anyone debug my program and get it to run.
#include <fstream>
#include <iostream>
#include <string>
#include <cstdlib>
#include <map>
using namespace std;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |