| | |
problem with arrays
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2009
Posts: 3
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Sep 2009
Posts: 435
Reputation:
Solved Threads: 51
0
#3 Oct 27th, 2009
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.
•
•
Join Date: Sep 2009
Posts: 435
Reputation:
Solved Threads: 51
0
#5 Oct 27th, 2009
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.
•
•
Join Date: Sep 2009
Posts: 435
Reputation:
Solved Threads: 51
0
#6 Oct 27th, 2009
•
•
•
•
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?
•
•
Join Date: Oct 2009
Posts: 3
Reputation:
Solved Threads: 0
0
#7 Oct 27th, 2009
C++ Syntax (Toggle Plain Text)
#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; }
Last edited by LSUchemist; Oct 27th, 2009 at 6:23 pm.
•
•
Join Date: Sep 2009
Posts: 435
Reputation:
Solved Threads: 51
0
#9 Oct 27th, 2009
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.
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.
Last edited by jonsca; Oct 27th, 2009 at 6:43 pm.
![]() |
Similar Threads
- (reformatted) How to return Multi-Dimensional Arrays (C++)
- Slight Problem with arrays. (Java)
- Newbie Problem: Arrays (C++)
- How can I access these arrays without ifs (C++)
- Help: Passing arrays between functions (C)
- Storing dynamic form values in Arrays for display & insert (PHP)
- beginner"problem in arrays help me in codes" (C)
Other Threads in the C++ Forum
- Previous Thread: Nested Lopp Asterisk Histogram
- Next Thread: C++ Using time.h [HELP !]
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg simple sorting string strings temperature template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





