简体   繁体   中英

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

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM