473,785 Members | 2,363 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

frequency analysis

I need to write a program to do a frequency analysis on a string of text.
Firstly I need to get the alphabet A to Z for comparison but I'm not sure
how to go about this.

Is the following the only way to do it:

Alphabet[26] = {'a','b','c',.. .,'z'};

or is there another way to represent the alphabet characters.
Thankyou
Nov 13 '05 #1
8 6342
In 'comp.lang.c', "Pete" <No****@blank.c om> wrote:
<...> I need to get the alphabet A to Z for comparison but I'm not sure
how to go about this.

Is the following the only way to do it:

Alphabet[26] = {'a','b','c',.. .,'z'};

or is there another way to represent the alphabet characters.


static char const Alphabet[26] = "abcdefghijklmn opqrstuvwxyz";

But if you want A to Z :

static char const Alphabet[26] = "ABCDEFGHIJKLMN OPQRSTUVWXYZ";

Beware, in both cases, despite the appearences, 'Alphabet' is /not/ a string
literal. str*() functions won't work. If you want string literals, just
remove the size:

static char const Alphabet[] = "abcdefghijklmn opqrstuvwxyz";
or
static char const Alphabet[] = "ABCDEFGHIJKLMN OPQRSTUVWXYZ";

--
-ed- em**********@no os.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 13 '05 #2
Pete wrote:
I need to write a program to do a frequency analysis on a string of text.
Firstly I need to get the alphabet A to Z for comparison but I'm not sure
how to go about this.

Is the following the only way to do it:

Alphabet[26] = {'a','b','c',.. .,'z'};

or is there another way to represent the alphabet characters.


char Alphabet[26];
int i;

for (i=0; i<26; i++) Alphabet[i] = 'a' + i;

There are also isalpha(), islower() and isupper() to consider
(#include <ctype.h>).

--
Allin Cottrell
Department of Economics
Wake Forest University, NC

Nov 13 '05 #3
In 'comp.lang.c', Allin Cottrell <co******@wfu.e du> wrote:
or is there another way to represent the alphabet characters.


char Alphabet[26];
int i;

for (i=0; i<26; i++) Alphabet[i] = 'a' + i;


Wrong advice. The alphabetic character values don't have to be consecutive in
C.

--
-ed- em**********@no os.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 13 '05 #4
Allin Cottrell wrote:
Pete wrote:
I need to write a program to do a frequency analysis on a string of text.
Firstly I need to get the alphabet A to Z for comparison but I'm not sure
how to go about this.

Is the following the only way to do it:

Alphabet[26] = {'a','b','c',.. .,'z'};

or is there another way to represent the alphabet characters.

char Alphabet[26];
int i;

for (i=0; i<26; i++) Alphabet[i] = 'a' + i;

This is plain wrong. There is no guarantee whatsoever that alphabetic
characters are consecutive nor in ascending order.

--
Bertrand Mollinier Toublet
"Uno no se muere cuando debe, sino cuando puede"
-- Cor. Aureliano Buendia

Nov 13 '05 #5

"Allin Cottrell" <co******@wfu.e du> wrote in message
news:bg******** ***@f1n1.spenet .wfu.edu...
Pete wrote:
I need to write a program to do a frequency analysis on a string of text. Firstly I need to get the alphabet A to Z for comparison but I'm not sure how to go about this.

Is the following the only way to do it:

Alphabet[26] = {'a','b','c',.. .,'z'};

or is there another way to represent the alphabet characters.


char Alphabet[26];
int i;

for (i=0; i<26; i++) Alphabet[i] = 'a' + i;

There are also isalpha(), islower() and isupper() to consider
(#include <ctype.h>).

--
Allin Cottrell
Department of Economics
Wake Forest University, NC


The C standard said

5.2.1 Character sets
"The values of the members of the execution character set are
implementation-defined."

Your teacher may told you that we can increase the 'A' char(65) to get 'B'
char(66), but it is not always correct. The characters defined by ASCII is
consecutive, but in C, it is 'implementation-defined'.

--
Jeff
Nov 13 '05 #6
Jeff wrote:
"Allin Cottrell" <co******@wfu.e du> wrote in message
news:bg******** ***@f1n1.spenet .wfu.edu...
Pete wrote:
I need to write a program to do a frequency analysis on a string of
text.
Firstly I need to get the alphabet A to Z for comparison but I'm not
sure
how to go about this.

Is the following the only way to do it:

Alphabet[26] = {'a','b','c',.. .,'z'};

or is there another way to represent the alphabet characters.


char Alphabet[26];
int i;

for (i=0; i<26; i++) Alphabet[i] = 'a' + i;

There are also isalpha(), islower() and isupper() to consider
(#include <ctype.h>).

--
Allin Cottrell
Department of Economics
Wake Forest University, NC

The C standard said

5.2.1 Character sets
"The values of the members of the execution character set are
implementation-defined."

Your teacher may told you that we can increase the 'A' char(65) to get 'B'
char(66), but it is not always correct. The characters defined by ASCII is
consecutive, but in C, it is 'implementation-defined'.


You're right. I recalled that the standard guarantees that the
digits '0' through '9' have consecutive numerical values and incorrectly
generalized this to the Latin alphabet.

Allin Cottrell

Nov 13 '05 #7
Pete wrote:
I need to write a program to do a frequency analysis on a string of text.
Firstly I need to get the alphabet A to Z for comparison but I'm not sure
how to go about this.

Is the following the only way to do it:

Alphabet[26] = {'a','b','c',.. .,'z'};

or is there another way to represent the alphabet characters.


static const char lower[] = "abcdefghijklmn opqrstuvwxyz";
static const char upper[] = "ABCDEFGHIJKLMN OPQRSTUVWXYZ";

But why restrict yourself to letters?

Here's a little frequency counter that counts /everything/, provided
UCHAR_MAX isn't too huge.

#include <limits.h>
#include <stdio.h>

int main(void)
{
unsigned long Count[UCHAR_MAX + 1] = {0};
int ch = 0;
while((ch = getchar()) != EOF)
{
++Count[ch];
}

/* do any output you wanted right here */

return 0;
}

--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #8
Emmanuel Delahaye <em**********@n oos.fr> writes:
But if you want A to Z :

static char const Alphabet[26] = "ABCDEFGHIJKLMN OPQRSTUVWXYZ";

Beware, in both cases, despite the appearences, 'Alphabet' is /not/ a string
literal.

str*() functions won't work. If you want string literals, just
remove the size:

static char const Alphabet[] = "abcdefghijklmn opqrstuvwxyz";


This is an abuse of the term "string literal", which is defined
in C99 6.4.5#2:

A character string literal is a sequence of zero or more
multibyte characters enclosed in double-quotes, as in "xyz".

"abcdefghijklmn opqrstuvwxyz" is a string literal.
`Alphabet' is merely a string.
--
int main(void){char p[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2155
by: christopher diggins | last post by:
I would like to survey how widespread the usage of smart pointers in C++ code is today. Any anecdotal experience about the frequency of usage of smart pointer for dynamic allocation in your own code or other people's code you have come across would be appreciated. I am also trying to identify the likelihood nad frequency of scenarios where smart pointer solutions would not be appropriate, i.e. for some reason such as performance or...
7
9699
by: Dung Ping | last post by:
Such as: <script> //code aaaa zzzz ccc
1
1793
by: John | last post by:
I can't find this in the manuals. I'm not interested in size of primary or secondary logs, what is a good rule of thumb for how many logs to cut in an hour in a busy OLTP and DW environment. I heard every 15 minutes was a good starting point. Thx, Flick
11
4380
by: NC Tim | last post by:
Hello, I think the question i have is fairly straightforward, but I can't seem to replicate the old SAS frequency procedure when I try to accomplish this in MS Access. anyway, i have about 10 questions on a survey that have a possible response range from 0-4. what I would like to do is simply show that for each question we had x amount of responses in each category, which amount to x percentage of all
19
3145
by: jason_box | last post by:
I'm alittle new at C and I'm trying to write a simple program that will record the frequency of words and just print it out. It is suppose to take stdin and I heard it's only a few lines but I'm not sure where to start. The only example I have to work with is if you ran the program say: File list contains: This is a test.
7
4057
by: Udhay | last post by:
How to get the frequency of an audio file and how to separate the low and high frequency of an audio file
1
1468
by: goldtech | last post by:
In Python 2.1 are there any tools to take a column from a DB and do a frequency analysis - a breakdown of the values for this column? Possibly a histogram or a table saying out of 500 records I have one hundred and two "301" ninety-eight "212" values and three-hundred "410"? Is SQL the way to for this? Of course there'd be 1000's of values....
8
4090
by: Andrew Savige | last post by:
I'm learning Python by reading David Beazley's "Python Essential Reference" book and writing a few toy programs. To get a feel for hashes and sorting, I set myself this little problem today (not homework, BTW): Given a string containing a space-separated list of names: names = "freddy fred bill jock kevin andrew kevin kevin jock" produce a frequency table of names, sorted descending by frequency. then ascending byname. For...
13
3739
by: umpsumps | last post by:
Hello, Here is my code for a letter frequency counter. It seems bloated to me and any suggestions of what would be a better way (keep in my mind I'm a beginner) would be greatly appreciated.. def valsort(x): res = for key, value in x.items(): res.append((value, key))
0
9647
marktang
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10356
Oralloy
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10161
jinu1996
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7506
isladogs
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6743
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5390
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3662
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2890
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.