I have an assignment to write a program using 1D and 2D parallel arrays with input coming from a .data file given to us. I am nearly a complete novice with writing code and right now I am having a very hard time getting my program to write any values from the arrays I created to my output file. I am not sure if it is an issue with the way I created the arrays, or the way I tried to output the information.

All of our work is done on the school's unix server, which we log into with putty on our own computers at home. If someone can tell me how to copy my work from the command prompt to paste here, so someone here could take a look at it for me, I'd really appreciate it.

Recommended Answers

All 8 Replies

what text editor in putty are you using? Can you not map your network drive and just open it in wordpad?

Get a secure FTP program (e.g., http://www.coreftp.com/ but there are many others, or if your school doesn't use SSH you could use the insecure one in windows,ftp.exe ) and you should be able to log into your shell account and transfer files.

The editor I'm using is pico. Thanks for the link Jonsca, I can get the file now, but the code is all in one line, is there a way to keep the indentions without having to manualy go back and do it myself?

The editor I'm using is pico. I'm sure there is a way to simply open it up in wordpad, but like I said I'm a newb and I don't really know how.

I just tested it with putty now, highlight and hit control-C. There's also a command in the system menu in the upper left corner for Copy All To Clipboard, but that gets all your login stuff too and didn't get the Pico session when I tried it.

The editor I'm using is pico. Thanks for the link Jonsca, I can get the file now, but the code is all in one line, is there a way to keep the indentions without having to manualy go back and do it myself?

There are converters (see http://en.wikipedia.org/wiki/CRLF for the reason why this occurs) but it's probably faster to do it by hand unless there are thousands of lines...

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>

using namespace std;

//PROTOTYPES
void SetFormat (ofstream& fout);
void Header (ofstream& fout);
void openFiles(ifstream& fin, ofstream& fout);
int FillArrays(ifstream& fin, int employeeID[], int employeeTitleCode[],
               int countPayHis[]);
void printArray(int employeeID[], int employeeTilteCode[],
               int payHistories[], ofstream& fout, int n);

const int MAX=50;


int main()
{
   ifstream fin;
   ofstream fout;
   int employeeID[MAX];
   int employeeTitleCode[MAX];
   int countPayHis[MAX];
   int n;

   openFiles(fin, fout);
   Header(fout);
   n = FillArrays(fin, employeeID, employeeTitleCode, countPayHis);
   printArray(employeeID, employeeTitleCode, countPayHis, fout, n);
   return 0;

}// end main

void Header(ofstream& fout)
   {
    fout<<"   BUSTER'S CATERING INC.\n\n"
          "   Employee Data Calculator\n";
   }

void openFiles(ifstream& fin, ofstream& fout)
   {
    fin.open("Employees.data");
    if(fin.fail())
       {
        cout<< "   The input file Employees.data failed to open.\n"
               "   This program will now close.\n";


        exit(1);
       }

     return;
    }

int FillArrays(ifstream& fin, int employeeID[], int employeeTitleCode[], int countPayHis[])
{
   int ct = 0;
   int i = 0;
   int j = 0;
   int k = 0;

   while(fin >> i)
   {
      fin >> j;
      fin >> k;
      employeeTitleCode[ct] = j;
      countPayHis[ct] = k;

      ct++;
   }
   return ct;
}


void printArray(int employeeID[], int employeeTitleCode[], int countPayHis[], ofstream& fout, int n)
{
   for(int ct = 0; ct < n; ct++)
   {
      fout << employeeID[ct];
      fout << employeeTitleCode[ct];
while(fin >> i)
   {
      fin >> j;
      fin >> k;
      employeeTitleCode[ct] = j;
      countPayHis[ct] = k;

      ct++;
   }
   return ct;
}


void printArray(int employeeID[], int employeeTitleCode[], int countPayHis[], ofstream& fout, int n)
{
   for(int ct = 0; ct < n; ct++)
   {
      fout << employeeID[ct];
      fout << employeeTitleCode[ct];
      fout << countPayHis[ct] << endl;

  }
   return;
}

Please put some code tags around it code /code (in brackets []) or highlight and hit the button on the toolbar of the editor

You need to either pass in your fin into PrintArray, or more likely create a new ifstream object. Same with your j and k of the PrintArray() (the first one). They don't exist in the local scope (skim back through your text to clarify this for yourself). For these you can create a new local variable within that function.
Also, you are trying to overload a function PrintArray() with the same signature (i.e., int,int,int,ofstream&,int). How will the compiler tell the difference between the two? (it seems like you meant the one that returns ct to have a return type)
And, you don't need the return statements in your void functions.

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.