Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Wut ? C

Name: Anonymous 2007-11-16 12:09

AviStruct* GetVideoInfo(char*file)
{
    AviStruct* MyVideo = (AviStruct*)s_alloc(sizeof(AviStruct));
    FILE*f = fopen(file,"rb");
    if (f)
    {
        unsigned int dwRate;
        unsigned int dwScale;
        unsigned int dwLength;
        fseek(f,0x84, SEEK_SET );
        fread(&dwRate,4,1,f);
        fseek(f,0x80, SEEK_SET );
        fread(&dwScale,4,1,f);
        fseek(f,0x8C, SEEK_SET );
        fread(&dwLength,4,1,f);
        fseek(f,0x40, SEEK_SET );
        fread(&MyVideo->width,4,1,f);
        fseek(f,0x44, SEEK_SET );
        fread(&MyVideo->height,4,1,f);
        MyVideo->fFps = (float)((float)(dwRate)/(float)(dwScale));
        MyVideo->fDuration = (float)((float)(dwLength)/(float)(MyVideo->fFps));
        return MyVideo;

    }
    return 0x0;
}

Name: Anonymous 2007-11-17 5:50

>>12
he forgot to desallocate his MyVideo in case the file doesn't exist
he doesn't fclose
there's extra float conversion
here's a fixed code for you
AviStruct* GetVideoInfo(char*file)
{
    AviStruct* MyVideo = (AviStruct*)s_alloc(sizeof(AviStruct));
    FILE*f = fopen(file,"rb");
    if (f)
    {
        unsigned int dwRate;
        unsigned int dwScale;
        unsigned int dwLength;
        fseek(f,0x84, SEEK_SET );
        fread(&dwRate,4,1,f);
        fseek(f,0x80, SEEK_SET );
        fread(&dwScale,4,1,f);
        fseek(f,0x8C, SEEK_SET );
        fread(&dwLength,4,1,f);
        fseek(f,0x40, SEEK_SET );
        fread(&MyVideo->width,4,1,f);
        fseek(f,0x44, SEEK_SET );
        fread(&MyVideo->height,4,1,f);
        MyVideo->fFps = ((float)(dwRate)/dwScale);
        MyVideo->fDuration = ((dwLength)/(MyVideo->fFps));
        fclose(f);
        return MyVideo;

    }
    //Could not open file
    freememory(MyVideo);
    return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List