After looking at the same few lines for an hour now, I cannot figure out why the user named input file isn't opening and the user named output file isn't even being created. I used the debugger in visual studio 05 to figure out the input file isn't being opened successfully. I am working on 2d arrays and playing with the individual elements and moving them around. I am still working on the screen output and I don't have to many comments to walk through the code easily.

example input file for code reading purposes:

2
3
abc
def
ghi
2
st
uv

Code:

#include <iostream>
#include <fstream>
using namespace std;
void reversemajor(char matrix[][5], char major[][5], int matrixsize);
void reverseminor(char matrix[][5], char minor[][5], int matrixsize);
int main()
{
    ifstream input;
    ofstream output;
    int numberofarrays, matrixsize, i, j, k;
    char infilename[30], outfilename[30];
    char matrix[5][5], arrays[5][5];
    char major[5][5], minor[5][5];
    cout << "Please enter the input file name." << endl;
    cin >> infilename;
    cout << "Please enter the output file name." << endl;
    cin >> outfilename;
    input.open(infilename);
    output.open(outfilename);
    input >> numberofarrays;
    for (i = 0; i < numberofarrays; i++)
    {
        input >> matrixsize;
        for (k = 0; k < matrixsize; k++)
            for (j = 0; j < matrixsize; j++)
                input >> matrix[k][j];
                                //reading each array element
        for (k = 0; k < matrixsize; k++)
        {
            for (j = 0; j < matrixsize; j++)
            {
                arrays[k][j] = matrix[k][j];
                                //making a copy of array
            }
            reversemajor(matrix, major, matrixsize);
            reverseminor(matrix, minor, matrixsize);
            for (k = 0; k < matrixsize; k++)
                for (j = 0; j < matrixsize; j++)
                    output << arrays[k][j];
                                        //outputting to file
            for (k = 0; k < matrixsize; k++)
                for (j = 0; j < matrixsize; j++)
                    output << major[k][j];
            for (k = 0; k < matrixsize; k++)
                for (j = 0; j < matrixsize; j++)
                    output << minor[k][j];
        }
    }
    input.close();
    output.close();
    return 0;
}

Recommended Answers

All 2 Replies

Use windows explorer to check the location of the input file -- it probably isn't in the folder you think it is. If no path is given the file must be in the same folder as the executable program. And the output file will also be written to the same folder that the executable is in.

ok thanks. i had to go through all my project folders and found that the default path for creating my projects was changed, and i was putting the file in the path i thought it was supposed to be in. stupid mistake, tho ill probably be back later.

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.