The purpose of this code is to:
1)Read in an existing text file called "mandelinput.txt", and create an array of those values. Its the, "importFile()" Lines 10 - 32.
2)Using the values now stored in the "testPic[ROWS][COLUMS]" array, I want to print out the values stored in each element of the array. Its the, "printArray()" Lines 35 - 45.
3)Using the values stored in the "testPic[ROWS][COLUMS]" array, I want to export them to a file called "mandeloutput.ppm". Its the, "exportArray()" Lines 48 - 72.
Problems:
I can foresee a problem when I try to read in values in my first function. Lines 1 through 4 of my input document are not values but letters.
My question is,
is it possible for me to skip those four first lines before I read in any values into my array?
(Maybe *inputFile << endl << endl << endl << endl;* in between lines 24 and 25.)
The next major problem I'm having is how to handle the array in between functions.
How do I export the values from the array created in my first function, into my other two functions?
Thanks for taking a look.
Input text document:
P3
# The P3 means colors are in ASCII, then 3 column and 10 rows,
# then 255 for max color, then RGB triplets
3 10
255
255 000 000 000 000 000 000 000 000
000 255 000 000 000 000 000 000 000
000 000 000 000 000 000 000 000 000
000 000 255 000 000 000 000 000 000
255 255 000 000 000 000 000 000 000
000 255 255 000 000 000 000 000 000
255 000 255 000 000 000 000 000 000
000 100 000 000 000 000 000 000 000
100 000 100 000 000 000 000 000 000
200 200 000 000 000 000 000 000 000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#include <iostream>
#include <fstream>
#define ROWS 10
#define COLUMS 9
using namespace std;
// Read file called mandelinput.txt and put into an array called testPic
void importFile(){
int testPic[ROWS][COLUMS];
ifstream inputFile;
inputFile.open("mandelinput.txt");
if (!inputFile)
{
cout << "Error opening file.\n";
}
for (int i = 0; i <= ROWS; i++){ //Rows
cout << endl;
for (int j = 0; j <= COLUMS; j++){//Colums
inputFile >> testPic[i][j];
// for see an error here, trying to read in lines 1 through 5
}
}
inputFile.close();
}
// Print out the testPic or any other array's
void printArray(int myArray[][ROWS][COLUMS]){
for (int i = 0; i <= ROWS; i++){
cout << endl;
for (int j = 0; j <= COLUMS; j++){
cout << " " << i << " " << j;
}
}
}
// Output testPic onto mandleoutput.ppm
void exportArray(int ouputArray[][ROWS][COLUMS]){
ofstream outputFile;
outputFile.open("mandeloutput.ppm");
if (!outputFile){
cout << "Error opening file.\n";
}
outputFile << "P3" << endl;
outputFile << "# information about the file" << endl;
outputFile << "# more information about the file" << endl;
outputFile << ROWS << " " << COLUMS << endl;
for(int i = 0; i <= ROWS; i++){
cout << endl;
for (int j = 0; j <= COLUMS; j++){
outputFile << ouputArray[i][j];
}
}
outputFile.close();
}
int main(){
//Call the importFile() function.
//Use the array created in importFile() function and use it in printArray() function.
//I tried printArray(importFile()); doesn't work. Still trying to
//grasp the concept of fuctions, and sending values.
//Use the array created in importFile() and use it in exportArray().
//Eventually I would like to add another function that creates an input
//for exportArray() that will randomize how the screen looks.
return 0;
}
|