error when converting FILE * to const char

0

Hello, I do not understand why I have an error (the one I mention in the title) on the next line

const char* filename = InFile;

the code is a bit extensive I'll leave the main

int main(int argc, char * argv[]){
    FILE* InFile = fopen(argv[1], "rb");

    const char* filename = InFile;
    DWORD crc = GetFileCRC32(filename);

    DWORD wSize = GetFileSize(InFile, NULL);
    printf("crc32: %lu %lu", crc, wSize);

    fclose(InFile);
}

update, how can I weigh a file to this function to generate the crc32?

DWORD GetFileCRC32(const char* c_szFileName)
{
    HANDLE hFile = CreateFile(c_szFileName,                 // name of the file
                         GENERIC_READ,                  // desired access
                         FILE_SHARE_READ,           // share mode
                         NULL,                      // security attributes
                         OPEN_EXISTING,         // creation disposition
                         FILE_ATTRIBUTE_NORMAL,     // flags and attr
                         NULL);                     // template file

    if (INVALID_HANDLE_VALUE == hFile)
        return 0;


    DWORD dwRetCRC32=GetHFILECRC32(hFile);

    CloseHandle(hFile);

    return dwRetCRC32;
}
    
asked by crt 19.02.2018 в 06:11
source

1 answer

4

The message can not be more clear and explicit:

FILE* InFile = fopen(argv[1], "rb");
//    ^^^^^^ InFile es un puntero de tipo FILE

const char* filename = InFile;
//                     ^^^^^^ Como se convierte esto en un const char*???

There is no conversion (neither implicit nor explicit) that allows you to go from FILE* to const char* .

If you want to get the name of the file ... Why do not you recover it from argv[1] ?

const char* filename = argv[1];

In any case, since you are in C ++, it is normal for you to use ifstream instead of FILE ...

    
answered by 19.02.2018 / 07:00
source