|
How would I tally the individual letters(upper and lower treated as one) and print out in descending order?
Output example:
Letter Z or z occurs 5 times
Letter B or b occurs 34 times
Also, how to calculate the ratio of that lower-case letter to the total count of that letter (upper case plus lower case)?
eg. b has 30 times, B has 4 times.
I would need to
Ratio = 30 / (30+4)
What code can I capture the individual letter count without hard coding?
|
|
|
|
|
use a map container...
TOXCCT >>> GEII power
|
|
|
|
|
Something like this:
struct SLetter
{
int iUpperCount;
int iLowerCount;
};
struct SAlphabet
{
SLetter m_Letters[26];
};
SAlphabet alphabet = {0};
char text[1024];
for (int i=0;i<length;i++)
{
int iIndex = 0;
int bLower = islower( text[i] );
if(bLower)
{
iIndex = text[i] -'a' ;// give the zero based index of the letter
alphabet.m_Letters[iIndex].iLowerCount ++;
}
else
{
iIndex = text[i] -'A' ; // give the zero based index of the letter
alphabet.m_Letters[iIndex].iUpperCount ++;
}
}
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
a map does this...
each letter is referenced once, and there is only the existing letters into it... (if there is no 't' in the text for example, why allocating space for it ?). better, if you don't use the same alphabet as our ??? will your 26-values array be efficient ?
more, a map associate to each letter (the keys), a value, which is here the ratios...
just define a map<char, int>
TOXCCT >>> GEII power
|
|
|
|
|
It was intended as an alternative, i never said its the best solution
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Thanks tp both coaches. Those two topics are new to me. I will read into structures and mapping. Will ask you guys more later.
|
|
|
|
|
Hi Papa:
can I call an input file(from a: drive) into an array? How?
|
|
|
|
|
Hi all..
How can i hide a scroll bar.Iam using a form based application.
|
|
|
|
|
Check ShowScrollBar( UINT nBar, BOOL bShow = TRUE );
nBar one of SB_BOTH, SB_HORZ and SB_VERT.
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I encountered the following compiler error with this code:
Are there solutions known allready?
Thanx for any comment
temp\dummy\main.cpp(35) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1794)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
Error executing cl.exe.
dummy.exe - 1 error(s), 0 warning(s)
<br />
#include "stdio.h"<br />
#include "memory.h"<br />
<br />
class test<br />
{<br />
template<typename t=""> void func(T a, T b);<br />
};<br />
<br />
void main ()<br />
{<br />
double test = 2;<br />
double *zC_arr = new double[10];<br />
memset(zC_arr, 0, sizeof(zC_arr));<br />
<br />
printf("%lf\n", &test::func<>(1,2));<br />
delete zC_arr;<br />
}<br />
<br />
template<typename t=""> void func(T a, T b)<br />
{<br />
return a+b;<br />
} <br />
<br />
F.Graefe
|
|
|
|
|
you must write template<typename T> ... (but might have done this).
could you give us the line 1794 which is repporting the compile error please ?
TOXCCT >>> GEII power
|
|
|
|
|
the Brackets <typename T> has been suppressed by posting the message.
unfortunately there is no file : msc1.cpp to be found!
Thats why I am asking
F Graefe
|
|
|
|
|
sounds silly but have you tried "Rebuild ALL"
i can't even remember what my point is now, but anyway, i'm correct
Barring unforeseen acts of God and Adminstrators, my server will be up tomorrow. I'm more worried about the Adminstrators.
|
|
|
|
|
Yes SIR
|
|
|
|
|
HMM I think i should not return a value on void deklaration !!!!!!
Thanks and cu
F Graefe:
|
|
|
|
|
There's another coding style for function templates by putting the return type of function template into a new line as:
template <class T><br />
<font color:red>void</font> FooBar(T& aa, T& bb)<br />
{<br />
<font color:red>return</font> aa - bb;<br />
}
Maxwell Chen
|
|
|
|
|
don't put either into "". even if the compiler does find it, prefer the standard notation for system includes, like <stdio.h>.
also, if you are coding in pure C++, you can use <cstdio> . that will have the consequence to put all standard functions into the std:: namespace.
TOXCCT >>> GEII power
|
|
|
|
|
msc1.cpp is a red herring: that's information for Microsoft support (it's the compiler's source file).
Visual C++ 6.0 didn't support member function templates very well, if at all. If you must do this, use Visual Studio .NET 2003. The C++ compiler toolset from VS.NET 2003 is available as the Visual C++ Toolkit 2003[^].
I was going to point out the many errors in this code, but I'm actually not going to, because I suspect it's an academic exercise.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Just want to convert short to array of bytes... Any idea ?
|
|
|
|
|
convert to what??
(and what are your arrays like ?)
TOXCCT >>> GEII power
|
|
|
|
|
Converting a "short" value to an array of bytes
|
|
|
|
|
Xtreme method here (with VC++ 7.0):
#include <iostream>
struct Foo
{
char Byte[0];
};
void main()
{
const int iSize = 5;
short nNum[iSize] = {1, 2, 3, 4, 5};
Foo* p = reinterpret_cast<Foo*>(nNum);
for(int i = 0; i < (iSize * 2); i++) {
int iTmp = p->Byte[i];
printf("%d ", iTmp);
}
}
<b>Maxwell Chen</b>
|
|
|
|
|
Simple:
short shValue;<br />
unsigned char byteArray[2];<br />
<br />
memcpy(byteArray, &shValue, 2);<br />
<br />
memcpy(&shValue, byteArray, 2);
But note that this code doesn't handle endianess correctly. If you want to handle endianess you must swap the two bytes on one (and only one!) system.
Best regards,
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
|
Dominik Reichl wrote:
If you want to handle endianess you must swap the two bytes on one (and only one!) system.
I would typically use htons on the sender and ntohs on the receiver (Host-to-Network Short, Network-to-Host Short). Those functions will convert between the network representation (always big-endian) and whatever the current (host) system is (little-endian for all Windows systems).
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|