How do I solve this error "error C2017: illegal escape sequence"

Hi Experts,
I have the following header and cpp code. UNfortunately when I try to build the solution in Visual, I get the following error.

error C2017: illegal escape sequence

Please tell me how I can solve this issue,

Thanks,

Dennis
#include <iostream>
#include <fstream>
#include <string>
 
using namespace std;
 
#define idx(PIC, i, j) \*(PIC->img + (i)*PIC->Width + (j))
 
/*** New Data Types ***/
typedef unsigned char BYTE;
 
 
// create data structure to hold image
struct PIC
{
    unsigned int nChannel;
    bool InterLeaved;
    unsigned int Width, Height, Maxval;
    BYTE *img;
};
 
 
 
//function that loads in the header
bool LoadP5Header(ifstream &infile, PIC &pic)
{
    bool rtv = true;
    char buf[16];
    int bufIndex;
    int width, height, maxval;
 
    infile.read(buf, 2); // get the magic number
    buf[2]='\0';
 
    if(buf[0] == 'P' && buf[1] == '5')
	{
        infile.read(buf, 1);
        while(isspace(buf[0])) // Skip white space(s)
		{
            infile.read(buf,1);
		}
 
        // get width
        bufIndex = 0;
        while(bufIndex < 15 && !isspace(buf[bufIndex]))
		{
            bufIndex++;
            infile.read(buf+bufIndex, 1);
        }
        buf[bufIndex] = NULL;  // null terminated string
        width = atoi(buf);
 
        // get height
        infile.read(buf,1);
        while(isspace(buf[0])) // Skip white space(s)
		{
            infile.read(buf,1);
        }
        bufIndex = 0;
        while(bufIndex < 15 && !isspace(buf[bufIndex]))
		{
            bufIndex++;
            infile.read(buf+bufIndex, 1);
        }
        buf[bufIndex] = NULL;  // null terminated string
        height = atoi(buf);
 
       // get Maxval
		infile.read(buf,1);
        while(isspace(buf[0])) // Skip white space(s)
		{
            infile.read(buf,1);
        }
        bufIndex = 0;
        while(bufIndex < 15 && !isspace(buf[bufIndex]))
		{
            bufIndex++;
            infile.read(buf+bufIndex, 1);
        }
        buf[bufIndex] = NULL;  // null terminated string
        maxval = atoi(buf);
 
		// Skip white space(s)
		infile.read(buf,1);
 
        // set the image information in the struct
        pic.InterLeaved = false;
        pic.Width = width;
        pic.Height = height;
		pic.Maxval = maxval;
 
    }
    else rtv = false;
 
    return rtv;
}; // end of LoadP5Header()
 
//function that accepts an infile object and a PIC Object
//and reads in the PIC object
void LoadImage(ifstream &infile, PIC &pic)
{
    infile.read(reinterpret_cast<char *>(pic.img), pic.Width*pic.Height);
}
 
//function that accepts an outstream file and a PIC object to
//and writes the output stream to the PIC object
void WritePGM(ofstream & outfile, PIC pic)
{
    outfile << "P5" << endl;
    outfile << pic.Width << " " << pic.Height << endl;
	outfile << pic.Maxval << endl;
 
    outfile.write(reinterpret_cast<char *>(pic.img), pic.Width*pic.Height);
}
 
 
void zoom_delete(struct PIC *In,  struct PIC *Out, int x, int y, int hor, int ver, unsigned char zd)
{
	int i = 0;
	int j = 0;
	int m = 0;
	int n = 0;
 
	if(zd)
	{
		for(i=y;i<ver;++i)
		{
			for(j=x;j<hor;++j){
 
				idx(Out, m, n) = idx(Out,m+1,n) = idx(Out,m,n+1) = idx(Out,m+1,n+1) = idx(In,j,i);
				n += 2;
			}
 
			 m += 2;
			 n = 0;
		}
	}
 
	else{
		for(i=y;i<ver;i+=2)
		{
			for(j=x; j<hor; j+=2)
			{
				idx(Out,m,n) = idx(In,i,j);
				++n;
			}
			++m;
			n = 0;
		}
	}
}
 
 
 
int main()
{  
	ifstream infile_Pin;                /* input file */
    ofstream outfile_Pout;            /* output file */
    char inFileName_Pin[128]="1.pgm";            /* input file name */
    char outFileName_Pout[128]="2.pgm";        /* ouput file name */
	
	int Npixels, i;
    PIC Pin;            //source image
    PIC Pout;            //output file
 
    /* open input/output file */
    infile_Pin.open(inFileName_Pin, ios::binary);
    outfile_Pout.open(outFileName_Pout, ios::binary);
 
	/* check input file */
    if(!infile_Pin)
    {
        cout<<"Cannot open input file "<< inFileName_Pin <<endl;
        return 1;
    }
 
    if (LoadP5Header(infile_Pin, Pin)) // load pgm (Pin) image header information
    {
        // allocate the memory for the input image
        //the dimensions of the original
        Pin.img = new BYTE[Pin.Width*Pin.Height];
 
        LoadImage(infile_Pin, Pin);
	
		// allocate memory for output images
        Pout.nChannel = 1;
        Pout.InterLeaved = false;
        Pout.Width = Pin.Width;
        Pout.Height = Pin.Height;
		Pout.Maxval = Pin.Maxval;
 
		Npixels = Pin.Width*Pin.Height;
        Pout.img = new BYTE [Npixels];
   
        //cout<<Npixels<< '\n';
       
        for (i=0;i<Npixels;i++)
		{
            Pout.img[i] = Pin.img[i];       
        }//end for loop
 
		//int pix=Pout.img[0];
		//cout<<pix<< endl;
		// output PGM (P5) images
        WritePGM(outfile_Pout, Pout);
	}
}

Open in new window

datopdogg7Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

datopdogg7Author Commented:
#ifndef read_H
#define read_H
 
#include <iostream>
#include <fstream>
 
using namespace std;
 
/*** New Data Types ***/
 
typedef unsigned char BYTE;
 
// Create Data Structure to Hold Image //
 
typedef struct PIC
{
        unsigned int nChannel;
        bool InterLeaved;
        unsigned int Width, Height, Maxval;
        BYTE *img;
} PIC;
 
bool LoadP5Header(ifstream &infile, PIC &pic);
 
void LoadImage(ifstream &infile, PIC &pic);
 
void WritePGM(ofstream & outfile, PIC pic);

void zoom_delete(struct PIC *In,  struct PIC *Out, int x, int y, int hor, int ver, unsigned char zd);
 
#endif
datopdogg7Author Commented:
Oh, and the error occurs at line 128 in the .cpp file, more specifically:

idx(Out,m,n) = idx(In,i,j);
abelCommented:
Try changing line 7 into this:

#define idx(PIC, i, j) *(PIC->img + (i)*PIC->Width + (j))

Open in new window

OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

evilrixSenior Software Engineer (Avast)Commented:
datodogg7, as I pointed out this thread, http:/Q_24430078.html#24448282 the header file you are now using contains a couple of issues. I strongly suggest you review that thread again. You'll se the question was reopened because the advice given was not completely correct.


Your problem in this question, I think, is line 7 you have this...

#define idx(PIC, i, j) \*(PIC->img + (i)*PIC->Width + (j))


The \ is actually a continuation char for macros and I suspect the original code was split over 2 lines thus

#define idx(PIC, i, j) \
      *(PIC->img + (i)*PIC->Width + (j))

If it was and you rolled it up into 1 line then you need to lose the \ so you should have this...

#define idx(PIC, i, j) *(PIC->img + (i)*PIC->Width + (j))

With this correction made the code above compiled under gcc

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
abelCommented:
Didn't know there was a related question. But conclusions are the same regardless ;-)
abelCommented:
Hey, we both came up with the same conclusion, no fair share of pts? ... :S ah well...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.