File CRC

How would one go about returning the CRC of a file given the name stored in a char*, in non-MFC C++ or C. I've been trying different things but just can't get it to work.
StateAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mnashadkaCommented:
You should check out the Boost library's CRC.  The documentation can be found at: http://www.boost.org/libs/crc/crc.html .  You just need to read the file into a buffer and call the process_bytes and checksum functions.  This header file should be able to be included in any relatively standard-conforming C++ compiler.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jaime OlivaresSoftware ArchitectCommented:
Some C code:

DWORD get_crc_32(char *filename)
{
    static unsigned long crc_table[256];
    static bool generated = false;
    unsigned long crc;
    FILE *fp;
    int c;
   
    if (!generated) {
        unsigned long crc, p;
        int    i, j;
   
        for (i = 0; i < 256; i++) {
            crc = i;
            for (j = 8; j > 0; j--) {
                if (crc & 1)
                    crc = (crc >> 1) ^ 0xEDB88320L;
                else
                    crc >>= 1;
            }
            crc_table[i] = crc;
        }
        generated = true;
    }

    if ( !(fp=fopen(filename, "rb")))
        return NULL;                               <------------------------ When error occurs, return 0

    crc = 0xFFFFFFFF;
    while ((c = getc(fp)) != EOF)
        crc = (crc>>8) ^ crc_table[ (crc^c) & 0xFF ];
    crc ^= 0xFFFFFFFF;

    fclose(fp);

    return CRC;
}
0
Jaime OlivaresSoftware ArchitectCommented:
Have provided a functions that does what author resquested, waiting for some feeback...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.