473,396 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need a few pointers in C

Hi, after a little help if possible please folks

I am wanting to create a program that accepts an input of characters using gets(), then analyse the string and count the occurance of each letter of the alphabet.

Is it possible to do this in one function, or would I have to repeat it 26 times?

Also, to attain this function, I was going to construct it from an IF statement that is nested in a WHILE loop.

Is the the best way of appraoching this problem, or is there a simpler solution?

Many thanks in advance
Nov 2 '06 #1
3 1312
cuteanu
14
Use a for loop from a to z and add up the no of times each alphabet occurs,
u will need a double for loop
Nov 8 '06 #2
r035198x
13,262 8TB
Use a for loop from a to z and add up the no of times each alphabet occurs,
u will need a double for loop
I suggest you use 2 functions
The first one takes a char array and a char and returns the position of this character in the array. If this is called say getPosition, then


in the other function or in main
Define a char[] called alphabet and initialise it with the 26 characters.
Define an int[] called frequencies of size 26 and initialise it with zeros.
You would use a for loop as suggested but it would not go from a to z but from 0 to the number of characters entered.
at each step of the for loop you do
frequencies[getPosition(alphabet, character)] = frequencies[getPosition(alphabet, character) ] + 1;

where character is the input character
Nov 8 '06 #3
cuteanu
14
try this:

include- iostream, stdio,string.h,
char n[50];
char x='A';
char s='a';
int f=0;
gets(n)
while (x<='Z' && s<='z')
{
for (int y=0;y<=strlen(n);y++)
{
if (x==n[y]||s==n[y])
f++;
}
cout<<"frequency of "<<x<<"is"<<f;
f=0;
x++;
s++;
}
Nov 8 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Tommy Lang | last post by:
I am working on this project and I need some help/pointers/comments to get me started, I am stuck. The program will be used to store information in an array while it is running. I need to store...
9
by: Simon | last post by:
Hi, if I have a structure like... struct sMyPointers{ ClassA *m_pPointerA; ClassB *m_pPointerB; void *m_pPointerToSomethingElse; };
0
by: rokuingh | last post by:
ok, so i've been working on this one for quite a while, and the code is very big so i'm just going to give the relevant parts. this is a program that builds polymers (chemical structures of repeated...
1
by: ArcInversion | last post by:
Hi, I've been using a javascript script to create a dragon that flies across the page. Anyways, I'd like to make it so when you click the dragon it takes you to a new page. Was wondering if anyone...
23
by: vinod.bhavnani | last post by:
Hello all, I need desperate help Here is the problem: My problem today is with multidimensional arrays. Lets say i have an array A this is a 4 dimensional static array.
11
by: sarathy | last post by:
Hi, I have been using C++ for a while. I am not entirely clear with the concepts of reference in C++. - Why was there a need for introducing a concept called "Reference" in C++ when everything...
5
by: Y2J | last post by:
I am working through this book on C++ programming, the author is speaking of using linked lists. He gave and example which I found confusing to say the least. So I rewrote the example in a way that...
20
by: Martin Jørgensen | last post by:
Hi, I'm reading a number of double values from a file. It's a 2D-array: 1 2 3 4 5 6 7 ------------- 1 3.2 2 0 2.1 3 9.3 4
7
by: DDP3000 | last post by:
void F(int **A, int N) { int i,j; for(i=0;i<N;i++) for(j=0;j<N;j++) A=((i+j)%2==0)?1:-1; } I have never used such a thing before, so it might be a really stupid question but I cannot find...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.