Problem with file path

Started by
1 comment, last by Mike555 9 years, 7 months ago

So i'm trying to load multiple files from a directory with for loop but i keep getting access violation and very strange path string.

Here is what i get in my path variable:


data/ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ0ùB

and here is the code used to make that variable:


Animation::Animation(std::string name, int framecount)
{
    char path[MAX_PATH];
    char *ext = ".bmp";
    frames = new SDL_Surface*[framecount];
    for (int k = 0; k < framecount; k++) {
        frames[k] = NULL;

        sprintf(path, "data/%s/f%i%s", name, k, ext);
        SDL_Surface *img = load_image(path);
        memset(&path[0], 0, sizeof(path)); // Clear tmp
    }

    maxFrames = framecount;
    currentFrame = 0;
}

I'm sure i'm doing something wrong with the char array but i just cant see it.

Advertisement

You probably meant to pass name.c_str() to sprintf. I think passing complex objects to a vararg function is undefined behaviour.

Thanks! That fixed it smile.png

This topic is closed to new replies.

Advertisement