Thread: passing file to function

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    3

    passing file to function

    Does anyone know of any good tutorials I can read for passing files to functions?

    I wish to read several predefined files and pass them to a CRC function (I'm yet to find a good one) for use inside a DLL.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    3
    They are binary files that contains nothing readable to a user.

    I'll try the first one out.


    I would really like to pass several files to a CRC function. I don't know if this one is suitable for use in a DLL. I can modify it to print the output to the correct place later.

    Code:
    void main(int argc, char *argv[])
    {
        fstream input;
    	{
    	       for (argv++; *argv; argv++)
    		    {
                input.clear();
                input.open(*argv, ios::in | ios::nocreate | ios::binary);
                if (!input)
                {
                   cerr << "Could not open " << *argv << "!\n";
                }
                else
                {
                    cout.setf(ios::hex, ios::basefield);
                    cout << "File: " << *argv
                         << ", CRC-32 : " << getCrc(input) << "\n";
                }
                input.close();
            }
        }
    }
    Code:
    unsigned long getCrc(fstream &in)
    {
        unsigned long crc = 0xffffffff;
        unsigned char ch;
        int index;
    
        while (in.get(ch))
        {
            index = ((crc ^ ch) & 0xff);
            crc = ((crc >> 8) & 0x00ffffff) ^ crcTable[index];
        }
    
        return (crc ^ 0xffffffff);
    }
    There is also the lookup table but I don't need to post that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 08:26 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM