Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib> //libraries
- #include <iostream>
- #include <fstream>
- using namespace std;
- const int resolution = 10; //constant
- ifstream infile;
- ofstream outfile; //if and ofstream initializers
- void readData(int header[2], int image[resolution][resolution],int &count);
- void print(int image[resolution][resolution], int count); //function
- //prototypes
- int header[2], image[resolution][resolution]; //arrays
- int main()
- {
- int count = 0;
- outfile.open("output.txt");
- infile.open("image.txt");
- if(!infile.is_open()) {
- cout << endl << "ERROR: Unable to open file" << endl;
- system("PAUSE");
- return 1;
- }
- readData(header, image, count); //calls functions
- print(image, count);
- infile.close();
- outfile.close();
- system("PAUSE");
- return 0;
- }
- void readData(int header[2], int image[resolution][resolution], int &count)
- {
- infile >> header[0] >> header[1]; //reads in headers
- while(!infile.eof()&& infile >> image[count][0]
- && infile >> image[count][1] //reads values into image
- && infile >> image[count][2]
- && infile >> image[count][3])
- count++;
- }
- void print(int image[resolution][resolution], int count)
- {
- int i, j, counter = 0;
- outfile << header[0] << " " << header[1] << endl; //prints header
- outfile.width(10);
- for(i = 0; i < count; i++) { //prints arrays
- if(counter >= header[0]) {
- outfile << "\n" << endl; //puts a new line between each color
- counter = 0;
- }
- for (j = 0; j < 4; j++) {
- outfile.width(10);
- outfile << image[i][j];
- }
- outfile << endl;
- counter++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement