here is my code so far
Expand|Select|Wrap|Line Numbers
- /*Write a program, which scans a file and counts the number of characters, the number of lines, and the number
- of alphabetic characters in the file.Have main() open the file and pass the file pointer to a function named count.
- Count passes back the number of characters and the number of alphabetic characters. main() prints the answers and closes the file.
- */
- #include<iostream>
- #include<fstream>
- using namespace std;
- char countline(char c);
- void valuefile(ifstream & in, ofstream & out);
- int main (){
- ifstream in;
- ofstream out;
- char inName[100];
- char outName[100];
- do{
- cout << "Enter name of plain text file:\n";
- cin >> inName;
- in.open(inName);
- if(!in.is_open()){
- cerr << "Failed to open " << inName << " - Now exiting\n";
- exit(-1);
- }
- }while(!in.is_open());
- do{
- cout << "Enter name for output file:\n";
- cin >> outName;
- out.open(outName);
- if(!out.is_open()){
- cerr << "Failed to open " << outName << " - Now exiting\n";
- exit(-1);
- }
- }while (!out.is_open());{
- valuefile(in,out);
- cout << "Output file is in " << outName << endl;
- }
- return 0;
- }
- char countline( char c){
- if (c == ' ' )
- return c + 1; // gives me a ! instead of adding amount of spaces
- else
- return c;
- }
- void valuefile(ifstream & in, ofstream & out){
- while( !in.eof()){
- char c = in.get();
- out << countline(c);
- }
- }
any input would help, thanks guys