bloomy
bloomy

Reputation: 33

debug assertion failed using sprintf in c++

I keep getting the "debug assertion failed" error when i debug my code

It seems to fail at the sprintf line in the function below:

void GetReference(int side)
{   
    for (int j=0; j<exposeNumber; j++)
    {
        image = cvQueryFrame(capture); // get the first frame of video

        sprintf(fileName, "RefImage%i", (side*exposeNumber + j));

        cvSaveImage(fileName, image);

        wait(200);

    }
}

"exposeNumber" is equal to 5 and "side" can either be 0 or 1

Cheers Chris

Upvotes: 0

Views: 1853

Answers (1)

Kiril Kirov
Kiril Kirov

Reputation: 38163

fileName MUST be big enough. And a char*. And not NULL. For example:

char fileName[1024];

or

char* fileName = new char[ 1024 ];
//..
delete[] fileName;

Or something smaller here. As I see, I guess 32 or 64 would be big enough.

I'm pretty sure the assertion fails because of NULL (or 0, which is the same here) pointer (fileName)

Upvotes: 4

Related Questions