Dynamischer Speicher
Verfasst: Sa Nov 20, 2010 3:41 pm
				
				Okay, folgendes Problem. Ich bin zurzeit dabei ein Programm zu schreiben. Dabei will ich Bilder aus einem Ordner in SDL_Surface laden. Das ganze wollte ich dynamisch machen, damit mein Array immer groß genug ist. Folgendes Problem ist diese Fehlermeldung:
Grund für den Fehler sind wohl folgende Zeilen:
Variablen:
Global:
Im Programm:
Codeauszug:
Hat jemand Ideen wie man das fixxen könnte? Die angesprochene Zeile der Fehlermeldung ist folgende:
			Code: Alles auswählen
no match for 'operator=' in '*(pictures + ((unsigned int)(((unsigned int)i) * 60u))) = IMG_Load(((const char*)(& image)))'Variablen:
Global:
Code: Alles auswählen
char img_path[256] = "images/"; // path to image folder
char image[512]; // universal variable for final imagepathCode: Alles auswählen
bool done = false;
    bool update_sprites = true;
    SDL_Surface *screen, *background;
    SDL_Surface *pictures;
    DIR *dip;
    struct dirent *dit;
    unsigned int filecounter = 0;
    long int avaible_files = 0;
    int i = 0;Code: Alles auswählen
if( ( dip = opendir( img_path ) ) == NULL )
    {
        printf( "opendir: Couldn't open directory %s\n", img_path );
        return 1;
    }
    while( ( dit = readdir( dip ) ) != NULL )
    {
        SDL_Surface* tmp;
        sprintf( image, "%s/%s", img_path, dit->d_name );
        tmp = IMG_Load( image );
        if( tmp )
            {
                filecounter++;
                avaible_files |= (long int)( pow( 2, i ) );
                SDL_FreeSurface( tmp );
            }
        i++;
    }
    printf( "Found %d JPG files in %s folder\n", filecounter, img_path );
    // allocate enough memory for the pictures
    pictures = (SDL_Surface*) calloc( filecounter, sizeof( SDL_Surface ) );
    // rewind directory and load all files into the allocated memory
    rewinddir( dip );
    i = 0;
    while( ( dit = readdir( dip ) ) != NULL )
    {
        if( avaible_files & (long int)( pow( 2, i ) ) )
        {
            sprintf( image, "%s/%s", img_path, dit->d_name );
            pictures[i] = IMG_Load( image );
        }
        i++;
    }
Code: Alles auswählen
pictures[i] = IMG_Load( image );
