I am new to filing and have not much idea about it.
I have written a code that tries to read an ASCII .pgm file named pic.pgm and writes it as mypic.pgm file:
#include <fstream>
const int MAXHEIGHT=221;
unsigned char *bitmap[MAXHEIGHT]={'\0'} ;// pointers to each pixel row
int main()
{
int width=201, height=221;
std::ifstream ifile("pic.pgm",std::ios::in);
std::ofstream ofile("mypic.pgm",std::ios::out);
for(int i=0;i<height;++i)
{
for(int j=0;j<width;++j)
ifile.read(bitmap[i][j],sizeof(bitmap));
}
ofile << "P2\n" << width << " " << height << "\n255\n";
for(int i=0;i<height;++i)
{
for(int j=0;j<width;++j)
ofile<<bitmap[i][j];
}
}
By my code has some errors. I will be thankful if anybody help me in correcting it.