C trying to open and close a file twice but my code wont wo

C++ .... trying to open and close a file twice, but my code wont work and I don\'t know why.

Full disclosure: I suck at programing, this class can\'t be over soon enough! This code should prompt the user for an input file (it does that), prompt the user for an intput file name (it does that too)...but at this point it stops working. In theory, after prompting for the output file name, the code should do stuff with the data from the input file, close the input and output file, open the files again, do more stuff, and then terminate. The final result should be an output file that looks like the bellow example.

Can you please look at this code and help me to figure out why it is not opening? If you see any other obvious mistake, please let me know as well. I am clueless on this thing. THANK YOU!

*********OUTPUT EXAMPLE***********

Message Report
- - - - - - - - - - - -
* Name:  Programer name
* Input File Name : p3in1.txt
* Output File Name: outPut_p3in1.txt
* Number of lines = 7
* Number of chars = 269
* Five Most Used Characters
\'E\' 33 counted
\'N\' 26 counted
\'T\' 25 counted
\'A\' 24 counted
\'R\' 21 counted
* Characters Not Used:   J, Q, Z,
________________________________________
Character Occurence
- - - - - - - - - - - -
A count = 24 B count =   2 C count =   5
D count =   8 E count = 33 F count =   7
G count =   4 H count = 10 I count = 19
J count =   0 K count =   2 L count = 18
M count =   6 N count = 26 O count = 18
P count =   5 Q count =   0 R count = 21
S count = 11 T count = 25 U count = 13
V count =   1 W count =   2 X count =   2
Y count =   7 Z count =   0
________________________________________
Original Message Contents
- - - - - - - - - - - -
9 8 7 6 5 You must have a line return after the
last character in your message, in order
for our example code to run properly. Note
that there are 8 lines of text in this file
including an additional mandatory \"blank line\"...otherwise
your system may hang up and create huge output files
the intentional line return and final blank line follows.
________________________________________
Character Stats: 346 total chars processed.
- - - - - - - - - - - - - - - - - - - - - - -
TYPE                   COUNT     PERCENT
-Digits                    6               0.017%
-UpperCase           2               0.006%
-HexDigit                85               0.246%
-Punctuation          8               0.023%
-Control                 7                0.020%
-LowerCase         267               0.772%
-AlpahNumer       275            0.795%
-Printable            339             0.980%
-Space                 63            0.182%

*******MY CODE IN C++ **************

//************************************************************
//
//************************************************************

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cctype>
#include <string>
#include <cstdio>
#include <sstream>

using namespace std;

///=====from goo.cpp 5 MOST USED CHARS======
typedef struct data
{
char ch;
int Count;
}data;
void Sort_array(struct data *List);
void writeMOSTuSED(ofstream& outtext, data *List,int char_count);
void copyMOSTuSED(char ch, struct data *List, int &char_count);

///=========================


void MYversionMostUSED(ofstream& outtext,int list[]);
void selectionSortWEBB(int length, int list[]);
void FileSTATS(char& ch, int list[]);
void FileSTATSout(ifstream& intext, ofstream& outtext, char& ch, int list[]);
void initialize(int& lc, int list[]);
void copyText(ifstream& intext, ofstream& outtext, char& ch, int list[]);
void characterCount(char ch, int list[]);
void printHeader(ofstream &out, string prograMer, string inFile, string outFile);
void writeTotal(ofstream& outtext, int lc, int list[]);

const int MAX_CODE_SIZE = 1000;

int main()
{

//Variable declaration
    string prograMer = \"name of programer\";
    ifstream inFile;    //input file stream variable
    ofstream outFile;   //output file stream variable
    string inputFile; //variable to store the name of the input file
    string outputFile;    //variable to store the name of the output file
    int lineCount; //stores the line count
    int letterCount[26]; //store the letter count A-Z...0-26
    char ch; //store the characters of file
    int char_count=0; //stores character count of the file
    struct data *List = new data[26]; //store the letter count A-Z...0-26
    int codeArray[MAX_CODE_SIZE];
    int codeLength;
    bool lengthCodeOk;

    //initialize array of struct
    for(int i=0;i < 26; i++)
    {
    List[i].ch = \'A\' + i;
    List[i].Count = 0;
    }


    //Open the I/O files

    cout << \"Enter the input file name: \";
    cin >> inputFile;
    cout << endl;
    inFile.open(inputFile.c_str());
    if (!inFile.is_open()) //If file is failed to open
    {
    cout << \"Cannot open the input file.\" << endl;
    return 1;
    }
    cout << \"Enter the output file name: \";
    cin >> outputFile;
    cout << endl;
    outFile.open(outputFile.c_str());

    //Reading file character by character
    while(inFile.get(ch))
    {
    copyMOSTuSED(ch,List,char_count);
    }
    //sort array of char and their count
    Sort_array(List);
    //Write data to output file
    writeMOSTuSED(outFile,List,char_count);

    //closing both input and output file 1st TIME
    inFile.close();
    outFile.close();

    inFile.open(inputFile.c_str());
    outFile.open(outputFile.c_str());
    if (!inFile)
    {
        cout << \"Cannot open the input file.\" << endl;
        return 1;
    }

    initialize(lineCount, letterCount);             //initialize lineCount & letterCount
    inFile.get(ch);                                 //read the first character
    while (inFile)
    {
        copyText(inFile, outFile, ch, letterCount); //process the lines
        lineCount++;                                //increment the line count
        inFile.get(ch);                             //read the next character
    }
    printHeader(outFile, prograMer, inputFile, outputFile);

    writeTotal(outFile, lineCount, letterCount);    //output # of lines and Char occurrence
    outFile <<endl;


    FileSTATSout(inFile, outFile, ch, letterCount);

      cout<<\"Done with writing data into output file\"<<endl;

    inFile.close();
    outFile.close();

    return 0;
}

void initialize(int& lc, int list[]) //initialize lineCount & letterCount to 0
{
    int j;
    lc = 0;

    for (j = 0; j < 26; j++)
        list[j] = 0;
}


void copyText(ifstream& intext, ofstream& outtext, char& ch, int list[]) //outputs Original message contents
{
    while (ch != \'\ \')      //process the entire line
    {
        outtext << ch;      //output the character
        characterCount(ch, list);   //call the function character count
        intext.get(ch);     //read the next character
    }
    outtext << ch;          //output the newline character
}

void characterCount(char ch, int list[]) //counting character occurrence
{
    int index;
    ch = toupper(ch);                       //convert letter to uppercase
    index = static_cast<int>(ch)- static_cast<int>(\'A\');        //Find the index array for this letter
    if (0 <= index && index < 26)           //IF the index is valid, add it to the appropriate count

        list[index]++;
}

void writeTotal(ofstream& outtext, int lc, int list[]) //outputs to output file. line & letter count
{
    int index;
    int char_count=0;
        for (index = 0; index < 26; index++)
    {
        char_count += list[index];
    }

    outtext << endl << endl;
    outtext << \"* Number of lines = \" << lc << endl;
    outtext << \"* Number of chars = \"<< char_count <<endl;

    MYversionMostUSED(outtext, list);
    outtext<<\"________________________________________\";
   outtext<<\"\ Character Occurence\ \";
   outtext <<\" - - - - - - - - - - - -\ \";

    for (index = 0; index<26; index = index + 3){

            if(index==23)

            outtext <<static_cast<char>(index+static_cast<int>(\'A\'))
            <<\" count= \"<< list[index]<<\"\\t\"
            <<static_cast<char>(index+static_cast<int>(\'A\')) <<\" count= \"<<list[index+1]<<endl;
    else
        outtext<<static_cast<char>(index+static_cast<int>(\'A\'))
        <<\" count= \"<< list[index]<<\"\\t\"
        <<static_cast<char>((index+1)+static_cast<int>(\'A\'))
        <<\" count= \"<<list[index+1]<<\"\\t\"

        <<static_cast<char>((index+2)+static_cast<int>(\'A\'))
        <<\" count= \"<<list[index+2]<<endl;
    }
}


void printHeader(ofstream &outtext, string prograMer, string inFile, string outFile)
{
    outtext << \"* Name: \" << prograMer << endl;
    outtext << \"* Input File Name : \" << inFile << endl;
    outtext << \"* Output File Name: \" << outFile << endl;
}

    void FileSTATS(char& ch, int list[]){
    int char_count=0;

    while(ch != \'\ \')
    {
        char_count++; //sum all chars
     //   outtext << ch;      //output the character

        if (isdigit(ch)) //0-9 digits
       {
            list[0]++;
       //     outtext << list[0];
        }
        else if(isupper(ch)) //UpperCase
        {
            list[1]++;
       //     outtext << list[1];

        }
        else if(isxdigit(ch)) //HexDigit
        {
            list[2]++;
            //outtext << list[2];
        }
            else if(ispunct(ch)) //Punctuation
        {
            list[3]++;
           // outtext << list[3];
        }
            else if(iscntrl(ch)) //Control
        {
            list[4]++;
       //    outtext << list[4];
        }
            else if(islower(ch)) //LowerCase
        {
            list[5]++;
       //     outtext << list[5];
        }
            else if(isalnum(ch)) //AlpahNumer
        {
            list[6]++;
        //    outtext << list[6];
        }
            else if(isprint(ch)) //Printable
        {
            list[7]++;
          // outtext << list[7];
        }
            else if(isspace(ch)) //Space
        {
            list[8]++;
         //   outtext << list[8];
        }
        else if(isalpha(ch)) //all letters?Number of chars??
        {
            list[9]++;
           // outtext << list[9];
        }
        else if(ch == \'\ \') //Number of lines??
        {
            list[10]++;
          // outtext << list[10];
        }
    } //end while loop

}

void FileSTATSout(ifstream& intext, ofstream& outtext, char& ch, int list[]){
    int char_count;
    string type[9] = {\"Digits\", \"UpperCase\",\"HexDigit \", \"Punctuation\",\"Control\",
                      \"LowerCase\",\"AlpahNumer\", \"Printable\",\"Space\"};

    FileSTATS(ch, list);
    outtext <<\"Character Stats: \"<<char_count<<\"total chars processed.\"<<endl;
    outtext <<\"------------------------------------------\"<<endl;
    outtext <<\"TYPE         COUNT     PERCENT\"<<endl;
    for(int index = 0;index<9;index++)
        outtext <<std::left<<setw(10)<<type[index];

    outtext << char_count;
    outtext << list[0];
    outtext << list[1];
    outtext << list[2];
    outtext << list[3];
    outtext << list[4];
    outtext << list[5];
    outtext << list[6];
    outtext << list[7];
    outtext << list[8];
   /* outtext << list[9];
    outtext << list[10];        */

    outtext << ch;     //output the newline character
}

void selectionSortWEBB(int length, int list[]) ///sorting down
{
    int index;
    int smallestIndex;
    int minIndex;
    int temp;
    for (index = 0; index < length - 1; index++)
    {
        //Step a
        smallestIndex = index;
        for (minIndex = index + 1; minIndex < length; minIndex++)
            if (list[minIndex] < list[smallestIndex])
                smallestIndex = minIndex;
                //Step b
                temp = list[smallestIndex];
                list[smallestIndex] = list[index];
                list[index] = temp;
   }
}


//Writing required data into output file
void MYversionMostUSED(ofstream& outtext,int list[]) //outputs to output file line & letter count
{
   int char_count, length;
   int iArray[26];

    outtext << \"Number of chars = \"<<char_count<<endl;
    outtext << \"Five Most Used Characters: \"<<endl;
    for (int i=0; i < 26; i++)
    {
        iArray[i] = i;
    }
    selectionSortWEBB(length, list);

    //cout <<\" * Five Most Used Characters\ \";
    outtext <<\" * Five Most Used Characters\ \";
    for (int i=0; i < 5; i++)
    {
    //    cout << \"\\t\\\'\" << static_cast<char>(indexArray[i] + static_cast<int>(\'A\'))
     //        << \"\\\' \" << list[i] << \" counted\ \";

        outtext << \"\\t\\\'\" << static_cast<char>(iArray[i] + static_cast<int>(\'A\'))
             << \"\\\' \" << list[i] << \" counted\ \";
        // << static_cast<char>(indexArray[index] + static_cast<int>(\'A\'))<<\"\ \"; NOT NEEDED
    }

      cout <<\" * Characters Not Used: \";
   outtext <<\" * Characters Not Used: \";

    for (int i=0; i < 26; i++){
      if(list[i]==0){
          cout<<\" \"<< static_cast<char>(iArray[i] + static_cast<int>(\'A\'))<<\", \";
       outtext<<\" \"<< static_cast<char>(iArray[i] + static_cast<int>(\'A\'))<<\", \";
       }//end if statement
    }//END FOR LOOP
    // cout <<\"\ \";
      outtext <<\"\ \";
}

//incrementing the count of alphabet
void copyMOSTuSED(char ch, struct data *List, int &char_count)//outputs Original message contents
{
//If alphabet belongs to a..z or A..Z
if((ch >= \'A\' && ch <= \'Z\') || (ch >= \'a\' && ch <= \'z\'))
{
List[toupper(ch) - \'A\'].Count += 1 ;
char_count++; //counting character
}
}
//Writing required data into output file
void writeMOSTuSED(ofstream& outtext, data *List,int char_count) //outputs to output file line & letter count
{
outtext << \"Number of chars = \"<<char_count<<endl;
outtext << \"Five Most Used Characters: \"<<endl;
for(int i=0; i < 5; i++)
    {
outtext <<\"\'\"<<List[i].ch<<\"\' \"<<List[i].Count<<\" counted\"<<endl;
}
outtext << \"Characters Not Used: \";
for(int i=0; i < 26; i++)
{
if(List[i].Count == 0)
{
outtext << List[i].ch <<\", \";
}
}
outtext << endl;
}
//bubble sort of array using count of alphabets as parameter
void Sort_array(struct data *List)
{
struct data temp;
for(int i = 1; i < 26; i++)
{
for(int j = 0; j < (26 - i); j++)
{
if(List[j].Count < List[j+1].Count)
{
temp.ch = List[j].ch;
temp.Count = List[j].Count;
List[j].ch = List[j+1].ch;
List[j].Count = List[j+1].Count;
List[j + 1].ch = temp.ch;
List[j + 1].Count = temp.Count;
}
}
}
}

Solution

In c++ programming the only possible way to open any file more than once is to use different stream variables each time...

So in the above given code different strem variables are used and solve the problem. Here the modified code is:

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cctype>
#include <string>
#include <cstdio>
#include <sstream>

using namespace std;

///=====from goo.cpp 5 MOST USED CHARS======
typedef struct data
{
char ch;
int Count;
}data;
void Sort_array(struct data *List);
void writeMOSTuSED(ofstream& outtext, data *List,int char_count);
void copyMOSTuSED(char ch, struct data *List, int &char_count);

///=========================


void MYversionMostUSED(ofstream& outtext,int list[]);
void selectionSortWEBB(int length, int list[]);
void FileSTATS(char& ch, int list[]);
void FileSTATSout(ifstream& intext, ofstream& outtext, char& ch, int list[]);
void initialize(int& lc, int list[]);
void copyText(ifstream& intext, ofstream& outtext, char& ch, int list[]);
void characterCount(char ch, int list[]);
void printHeader(ofstream &out, string prograMer, string inFile, string outFile);
void writeTotal(ofstream& outtext, int lc, int list[]);

const int MAX_CODE_SIZE = 1000;

int main()
{

//Variable declaration
    string prograMer = \"name of programer\";
    ifstream inFile,inFile1;    //input file stream variable
    ofstream outFile,outFile1;   //output file stream variable
    string inputFile; //variable to store the name of the input file
    string outputFile;    //variable to store the name of the output file
    int lineCount; //stores the line count
    int letterCount[26]; //store the letter count A-Z...0-26
    char ch; //store the characters of file
    int char_count=0; //stores character count of the file
    struct data *List = new data[26]; //store the letter count A-Z...0-26
    int codeArray[MAX_CODE_SIZE];
    int codeLength;
    bool lengthCodeOk;

    //initialize array of struct
    for(int i=0;i < 26; i++)
    {
    List[i].ch = \'A\' + i;
    List[i].Count = 0;
    }


    //Open the I/O files

    cout << \"Enter the input file name: \";
    cin >> inputFile;
    cout << endl;
    inFile.open(inputFile.c_str());
    if (!inFile.is_open()) //If file is failed to open
    {
    cout << \"Cannot open the input file.\" << endl;
    return 1;
    }
    cout << \"Enter the output file name: \";
    cin >> outputFile;
    cout << endl;
    outFile.open(outputFile.c_str());

    //Reading file character by character
    while(inFile.get(ch))
    {
    copyMOSTuSED(ch,List,char_count);
    }
    //sort array of char and their count
    Sort_array(List);
    //Write data to output file
    writeMOSTuSED(outFile,List,char_count);

    //closing both input and output file 1st TIME
    inFile.close();
    outFile.close();

    inFile1.open(inputFile.c_str());
    outFile1.open(outputFile.c_str());
    if (!inFile1)
    {
        cout << \"Cannot open the input file.\" << endl;
        return 1;
    }

    initialize(lineCount, letterCount);             //initialize lineCount & letterCount
    inFile1.get(ch);                                 //read the first character
    while (inFile1)
    {
        copyText(inFile1, outFile1, ch, letterCount); //process the lines
        lineCount++;                                //increment the line count
        inFile1.get(ch);                             //read the next character
    }
    printHeader(outFile1, prograMer, inputFile, outputFile);

    writeTotal(outFile1, lineCount, letterCount);    //output # of lines and Char occurrence
    outFile1 <<endl;


    FileSTATSout(inFile1, outFile1, ch, letterCount);

      cout<<\"Done with writing data into output file\"<<endl;

    inFile1.close();
    outFile1.close();

    return 0;
}

void initialize(int& lc, int list[]) //initialize lineCount & letterCount to 0
{
    int j;
    lc = 0;

    for (j = 0; j < 26; j++)
        list[j] = 0;
}


void copyText(ifstream& intext, ofstream& outtext, char& ch, int list[]) //outputs Original message contents
{
    while (ch != \'\ \')      //process the entire line
    {
        outtext << ch;      //output the character
        characterCount(ch, list);   //call the function character count
        intext.get(ch);     //read the next character
    }
    outtext << ch;          //output the newline character
}

void characterCount(char ch, int list[]) //counting character occurrence
{
    int index;
    ch = toupper(ch);                       //convert letter to uppercase
    index = static_cast<int>(ch)- static_cast<int>(\'A\');        //Find the index array for this letter
    if (0 <= index && index < 26)           //IF the index is valid, add it to the appropriate count

        list[index]++;
}

void writeTotal(ofstream& outtext, int lc, int list[]) //outputs to output file. line & letter count
{
    int index;
    int char_count=0;
        for (index = 0; index < 26; index++)
    {
        char_count += list[index];
    }

    outtext << endl << endl;
    outtext << \"* Number of lines = \" << lc << endl;
    outtext << \"* Number of chars = \"<< char_count <<endl;

    MYversionMostUSED(outtext, list);
    outtext<<\"________________________________________\";
   outtext<<\"\ Character Occurence\ \";
   outtext <<\" - - - - - - - - - - - -\ \";

    for (index = 0; index<26; index = index + 3){

            if(index==23)

            outtext <<static_cast<char>(index+static_cast<int>(\'A\'))
            <<\" count= \"<< list[index]<<\"\\t\"
            <<static_cast<char>(index+static_cast<int>(\'A\')) <<\" count= \"<<list[index+1]<<endl;
    else
        outtext<<static_cast<char>(index+static_cast<int>(\'A\'))
        <<\" count= \"<< list[index]<<\"\\t\"
        <<static_cast<char>((index+1)+static_cast<int>(\'A\'))
        <<\" count= \"<<list[index+1]<<\"\\t\"

        <<static_cast<char>((index+2)+static_cast<int>(\'A\'))
        <<\" count= \"<<list[index+2]<<endl;
    }
}


void printHeader(ofstream &outtext, string prograMer, string inFile, string outFile)
{
    outtext << \"* Name: \" << prograMer << endl;
    outtext << \"* Input File Name : \" << inFile << endl;
    outtext << \"* Output File Name: \" << outFile << endl;
}

    void FileSTATS(char& ch, int list[]){
    int char_count=0;

    while(ch != \'\ \')
    {
        char_count++; //sum all chars
     //   outtext << ch;      //output the character

        if (isdigit(ch)) //0-9 digits
       {
            list[0]++;
       //     outtext << list[0];
        }
        else if(isupper(ch)) //UpperCase
        {
            list[1]++;
       //     outtext << list[1];

        }
        else if(isxdigit(ch)) //HexDigit
        {
            list[2]++;
            //outtext << list[2];
        }
            else if(ispunct(ch)) //Punctuation
        {
            list[3]++;
           // outtext << list[3];
        }
            else if(iscntrl(ch)) //Control
        {
            list[4]++;
       //    outtext << list[4];
        }
            else if(islower(ch)) //LowerCase
        {
            list[5]++;
       //     outtext << list[5];
        }
            else if(isalnum(ch)) //AlpahNumer
        {
            list[6]++;
        //    outtext << list[6];
        }
            else if(isprint(ch)) //Printable
        {
            list[7]++;
          // outtext << list[7];
        }
            else if(isspace(ch)) //Space
        {
            list[8]++;
         //   outtext << list[8];
        }
        else if(isalpha(ch)) //all letters?Number of chars??
        {
            list[9]++;
           // outtext << list[9];
        }
        else if(ch == \'\ \') //Number of lines??
        {
            list[10]++;
          // outtext << list[10];
        }
    } //end while loop

}

void FileSTATSout(ifstream& intext, ofstream& outtext, char& ch, int list[]){
    int char_count;
    string type[9] = {\"Digits\", \"UpperCase\",\"HexDigit \", \"Punctuation\",\"Control\",
                      \"LowerCase\",\"AlpahNumer\", \"Printable\",\"Space\"};

    FileSTATS(ch, list);
    outtext <<\"Character Stats: \"<<char_count<<\"total chars processed.\"<<endl;
    outtext <<\"------------------------------------------\"<<endl;
    outtext <<\"TYPE         COUNT     PERCENT\"<<endl;
    for(int index = 0;index<9;index++)
        outtext <<std::left<<setw(10)<<type[index];

    outtext << char_count;
    outtext << list[0];
    outtext << list[1];
    outtext << list[2];
    outtext << list[3];
    outtext << list[4];
    outtext << list[5];
    outtext << list[6];
    outtext << list[7];
    outtext << list[8];
   /* outtext << list[9];
    outtext << list[10];        */

    outtext << ch;     //output the newline character
}

void selectionSortWEBB(int length, int list[]) ///sorting down
{
    int index;
    int smallestIndex;
    int minIndex;
    int temp;
    for (index = 0; index < length - 1; index++)
    {
        //Step a
        smallestIndex = index;
        for (minIndex = index + 1; minIndex < length; minIndex++)
            if (list[minIndex] < list[smallestIndex])
                smallestIndex = minIndex;
                //Step b
                temp = list[smallestIndex];
                list[smallestIndex] = list[index];
                list[index] = temp;
   }
}


//Writing required data into output file
void MYversionMostUSED(ofstream& outtext,int list[]) //outputs to output file line & letter count
{
   int char_count, length;
   int iArray[26];

    outtext << \"Number of chars = \"<<char_count<<endl;
    outtext << \"Five Most Used Characters: \"<<endl;
    for (int i=0; i < 26; i++)
    {
        iArray[i] = i;
    }
    selectionSortWEBB(length, list);

    //cout <<\" * Five Most Used Characters\ \";
    outtext <<\" * Five Most Used Characters\ \";
    for (int i=0; i < 5; i++)
    {
    //    cout << \"\\t\\\'\" << static_cast<char>(indexArray[i] + static_cast<int>(\'A\'))
     //        << \"\\\' \" << list[i] << \" counted\ \";

        outtext << \"\\t\\\'\" << static_cast<char>(iArray[i] + static_cast<int>(\'A\'))
             << \"\\\' \" << list[i] << \" counted\ \";
        // << static_cast<char>(indexArray[index] + static_cast<int>(\'A\'))<<\"\ \"; NOT NEEDED
    }

      cout <<\" * Characters Not Used: \";
   outtext <<\" * Characters Not Used: \";

    for (int i=0; i < 26; i++){
      if(list[i]==0){
          cout<<\" \"<< static_cast<char>(iArray[i] + static_cast<int>(\'A\'))<<\", \";
       outtext<<\" \"<< static_cast<char>(iArray[i] + static_cast<int>(\'A\'))<<\", \";
       }//end if statement
    }//END FOR LOOP
    // cout <<\"\ \";
      outtext <<\"\ \";
}

//incrementing the count of alphabet
void copyMOSTuSED(char ch, struct data *List, int &char_count)//outputs Original message contents
{
//If alphabet belongs to a..z or A..Z
if((ch >= \'A\' && ch <= \'Z\') || (ch >= \'a\' && ch <= \'z\'))
{
List[toupper(ch) - \'A\'].Count += 1 ;
char_count++; //counting character
}
}
//Writing required data into output file
void writeMOSTuSED(ofstream& outtext, data *List,int char_count) //outputs to output file line & letter count
{
outtext << \"Number of chars = \"<<char_count<<endl;
outtext << \"Five Most Used Characters: \"<<endl;
for(int i=0; i < 5; i++)
    {
outtext <<\"\'\"<<List[i].ch<<\"\' \"<<List[i].Count<<\" counted\"<<endl;
}
outtext << \"Characters Not Used: \";
for(int i=0; i < 26; i++)
{
if(List[i].Count == 0)
{
outtext << List[i].ch <<\", \";
}
}
outtext << endl;
}
//bubble sort of array using count of alphabets as parameter
void Sort_array(struct data *List)
{
struct data temp;
for(int i = 1; i < 26; i++)
{
for(int j = 0; j < (26 - i); j++)
{
if(List[j].Count < List[j+1].Count)
{
temp.ch = List[j].ch;
temp.Count = List[j].Count;
List[j].ch = List[j+1].ch;
List[j].Count = List[j+1].Count;
List[j + 1].ch = temp.ch;
List[j + 1].Count = temp.Count;
}
}
}
}

C++ .... trying to open and close a file twice, but my code wont work and I don\'t know why. Full disclosure: I suck at programing, this class can\'t be over so
C++ .... trying to open and close a file twice, but my code wont work and I don\'t know why. Full disclosure: I suck at programing, this class can\'t be over so
C++ .... trying to open and close a file twice, but my code wont work and I don\'t know why. Full disclosure: I suck at programing, this class can\'t be over so
C++ .... trying to open and close a file twice, but my code wont work and I don\'t know why. Full disclosure: I suck at programing, this class can\'t be over so
C++ .... trying to open and close a file twice, but my code wont work and I don\'t know why. Full disclosure: I suck at programing, this class can\'t be over so
C++ .... trying to open and close a file twice, but my code wont work and I don\'t know why. Full disclosure: I suck at programing, this class can\'t be over so
C++ .... trying to open and close a file twice, but my code wont work and I don\'t know why. Full disclosure: I suck at programing, this class can\'t be over so
C++ .... trying to open and close a file twice, but my code wont work and I don\'t know why. Full disclosure: I suck at programing, this class can\'t be over so
C++ .... trying to open and close a file twice, but my code wont work and I don\'t know why. Full disclosure: I suck at programing, this class can\'t be over so
C++ .... trying to open and close a file twice, but my code wont work and I don\'t know why. Full disclosure: I suck at programing, this class can\'t be over so
C++ .... trying to open and close a file twice, but my code wont work and I don\'t know why. Full disclosure: I suck at programing, this class can\'t be over so
C++ .... trying to open and close a file twice, but my code wont work and I don\'t know why. Full disclosure: I suck at programing, this class can\'t be over so
C++ .... trying to open and close a file twice, but my code wont work and I don\'t know why. Full disclosure: I suck at programing, this class can\'t be over so
C++ .... trying to open and close a file twice, but my code wont work and I don\'t know why. Full disclosure: I suck at programing, this class can\'t be over so

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site