Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
i don't figure what's the error here can anyone help
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>using namespace std;
class Histogram{
public:
string word;
string msg[];
int array[];
int length;
int freq[];
ifstream infile;
void open();
void frequency(int array[],int count);
int alpha();
};
void Histogram::open()
{
infile.open("msg.txt");
if(infile.fail())
{
cout<<"File cannot be open"<<endl;
exit(0);
}
infile>>word;
length=strlen(word.c_str());
for(int i=0;i<length;i++)
{
infile >> msg[i];
if(infile.eof())
break;
}
infile.close();
frequency(msg[],length);
}
void Histogram::frequency(int array[],int count)
{
atoi(array[].c_str());
for(int i=0;i<26;i++)
freq[i]=0;
for(int j=0;j<count;j++)
++freq[array[j]];
for(int rating =1;rating<=26;rating++)
{
cout <<freq[rating];
for(int k=1;k<=freq[rating];k++)
{
cout <<'*';
cout<<endl;
}
}
system("pause");
}

Hi,
You have a group of errors:
1) You can NOT define an array in C++ without giving it's size.
e.g. string msg[2];
int array[2];
int length;
int freq[2];
2) in the last line of the constructor, you are calling frequency(msg[],length);
How can you do that while you defined frequency() to be void frequency(int array[],int count);
3) In the 1st line of frequency, you are calling atoi() on an array of integers! atoi takes const char* as input.--
mohameda@ieee.org

thanks for reminding me..
but i still don't understand how am i going to change the string array into a const char array..
thanks for ur help!!

Wow, ignore that last post, susu
"You can NOT define an array in C++ without giving it's[sic] size."
-Yes you can, it's called a pointer.
This declaration:
void frequency(int array[],int count);
is just fine.
However, when not used as an argument to a function, you should just declare it as a pointer:
int* array;"in the last line of the constructor, you are calling frequency(msg[],length);
How can you do that while you defined frequency() to be void frequency(int array[],int count);"
-Uhh...there is no constructor defined in this code.
He is right, however, that you can't send msg[] as an argument. For one thing, that's not a valid argument. If you want to send the address of msg to the function (which would be useless, because both functions are members of the same class), you'd have to use simply msg (assuming msg is an array of strings), or &msg (if msg is just a string variable, which I believe is what you want it to be)Now, onto your code. Susu, I'm not entirely sure what you're trying to do here. What is the purpose of the array[] array in Frequency()? What is the purpose of the seperate *array array in Histogram? Why are you trying to make an array of strings?
I'm going to need more information about what your crazy code is trying to do before I can help you any further.Hope that helps.
BlueRaja.admin@gmail.com

![]() |
Large Random Numbers in C...
|
Update Batch file from Ba...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |