Write a program which reads a text from a file declared by the user.
If the file does not exist a message should state this and the program
should be terminated.
If the file opens with success the program should read the text and then output the uppercase letters A-Z and each of their counts and same of the lowercase letters a-z.
The program will then print the percentages of capital letters for every letter A-Z and small letters for every letter a-z to the output file also declared the user.

This program's main function should be a bunch of function calls and declarations. and the information for the count function should be put into an array of structures, and the information should be passed as reference also the input and output files should be passed as reference.
Also there are to be no global variables.Please help me someone. thanks in advance.
Below is what I have done so far:

#include <iostream> 
#include <fstream> 
#include <string> 

using namespace std; 

struct letters 
{ 
char ch; 
int lcount; 
}; 


void main() 
{ 
void Explanation(); 
int OpenFile(ifstream&, ofstream&); 
int Count(ifstream&, letters[], int); 
void PrintResult(letters[], int); 

const int Size = 52; 
letters List; 

ifstream infile; 
ofstream outfile; 

Explanation(); 
OpenFile(infile, outfile); 
Initialize(List, Size); 
Count(infile, List, Size); 
PrintResult(List, Size); 

} 

void Explanation() 
{ 
cout << "This program reads a text from a file declared by you the user." << endl; 
cout << "If the file does not exist a message will state this and the program\n" 
<< "will be terminated." << endl << endl; 
cout << "If the file opens with success the program will read the text and then\n" 
<< "output the letters in that file, both upper and lower case and the count\n" 
<< "of each letters appearance in the file." << endl << endl; 
cout << "The program will then print the total number as well as the percentages of\n" 
<< "capital letters for every letter A-Z and small letters for every letter a-z\n" 
<< "to the output file also declared by you the user." << endl << endl << endl; 
} 

int OpenFile(ifstream& infile, ofstream& outfile) 
{ 
string inputfile; 
string outputfile; 

cout << "Please enter the name for the input file: "; 
cin >> inputfile; 
cout << endl; 

infile.open(inputfile.c_str()); 

if (!infile) 
{ 
cout << "Cannot open the input file!" << endl; 
return 1; 
} 

cout << "Now enter the name for the output file: "; 
cin >> outputfile; 
cout << endl; 

outfile.open(outputfile.c_str()); 
}

ok had a chance to skim.... but void main?? main always returns a value...
int main(void)

or

int main()

not sure what the problems are could you state them? and please use code tags

ok had a chance to skim.... but void main?? main always returns a value...
int main(void)

or

int main()

not sure what the problems are could you state them? and please use code tags

void main is acceptable it is usually more common with programmers using MSVC based compilers (nmake).

also why are you declaring the file streams in main? You should jsut point the open file function the the file name where it declares and instanciates the file streams. If you need to count lines, do it in the Open function and return that value, then use that returned value in main.

anyways, just skimming through it.

>void main is acceptable
The language standard explicitly states that main must return an int. This has always been the case, except in the past the language has been imprecise enough for some to misinterpret it. Some compilers support void main, but only to cater to stupid people who don't know what language they're using.

read


http://homepages.tesco.net/~J.deBoynePollard/FGA/legality-of-void-main.html

Unfortunetly there is a valid claim to using void main(). It's bad practice, but does; technically, follow the standard (the specific standard mentioned in that article).

Been there, done that. I like this:

Even if your compiler accepts "void main()" avoid it, or risk being considered ignorant by C and C++ programmers.

"Hey, boss, the following code may or may not work -- it's behavior is unspecified*!"

*behavior where two or more possibilities exist and no further requirements on which is chosen in any instance


[edit]Follow some of the links and find that corrections have been made. Or that fun restrictions apply:

If you declare main or wmain as returning void, you cannot return an exit code to the parent process or operating system using a return statement; to return an exit code when main or wmain are declared as void, you must use the exit function.

i need your help.is it possible to give a solution to the following problem.
Store random numbers into two-dimensional array of 6 * 6 and interchange first 3 rows with last three rows.
i would be grateful to hear from you soon.
thank you in advance.

i need your help.is it possible to give a solution to the following problem.
Store random numbers into two-dimensional array of 6 * 6 and interchange first 3 rows with last three rows.
i would be grateful to hear from you soon.
thank you in advance.

Since this has nothing to do with this thread, it would have been better to have started a new one. Of course it is possible -- please post your initial attempt (and please use code tags).

>does; technically, follow the standard
Technically, no. Technically, the standard allows for non-portable extensions, but doesn't specify those extensions in any way. Therefore, void main does not follow the standard. It only has the potential for implementation-defined behavior rather than undefined behavior if the implementation documents it.

Your argument could be applied to any language or library extension.

Messages have been restored, sorry for the inconvience!

I stand corrected on this issue ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.