#include<iostream>
#include<fstream>
#include<string>
using namespace std;

void main()
{


	//decleration
	ifstream source;
	ofstream target;
	char * box;
	int width, height, numlevel;
	string s;
	int amount= 100;

	//--------------------

	source.open("1.ppm",ios::binary);
	while(source.fail())
	{
		cout<<"can not open the file"<<endl;    // to make sure the file is opened
	}

	source>> s;
	if ( s != "P6" )
	cout<<" the file is invailid " <<endl;

	source>> width>>height >>numlevel;

	source.get();

	// start reading into the array

	box= new char[width*height*3];
	source.read(box,width*height*3);
	source.close();

	for ( int i=0; i<height; i++ )
		for( int j=0; j<width; j++ )
	{
		unsigned char red= box[i*width*3 + j*3 ]; 
		unsigned char green= box[i*width*3 + j*3 + 1];
		unsigned char blue= box[i*width*3 + j*3 + 2];

		if ( (red + amount > 255) )
			red = 255;
		else if( red + amount < 0 )
		red = 0;
		else red+=amount;

		if ( (green + amount > 255) )
			green = 255;
		else if( green + amount < 0 )
		green = 0;
		else green+=amount;

		if ( (blue + amount > 255) )
			blue = 255;
		else if( blue + amount < 0 )
		blue = 0;
		else blue+=amount;

		box[i*width*3 + j*3] = red ;
	    box[i*width*3 + j*3 + 1] = green;
	    box[i*width*3 + j*3 + 2] = blue;

		//---------------------
		//writing to new file

		target.open("new.ppm");

		target << s << width<<height<< numlevel;
		
		for( int k=0; k<width*height*3; k++)
		target<<box[k];

		
		while(target.fail() )
			cout<<"can't write"<<endl;
		target.close();







}

cout<<" hello"<<endl;





}

I have a problem with this code. The program never does the goal. it never reaches the "cout<<"" line thats line 92 i waited like 5 minutes but nothing happened. moreover i think the code which writes to ppm file is missing somthing. but i don't know what. may be spaces between s height, width and numlevel.

pleas anyone give me a help

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.