Tell me what is the error in my code? The ReadFile function returns false. If you comment out the line "num = num * 10 + ((const char) lengthStrFile [i] - '0');" then the reading is normal. what is the problem?

HANDLE FileHandle = CreateFile((LPCWSTR)TEXT("file.txt"), GENERIC_READ, NULL, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); char * lengthStrFile; DWORD bytesRead; bool isOk ; int num = 0; int j; isOk = ReadFile(FileHandle, lengthStrFile, sizeof(char) * 8, &bytesRead, NULL); for (int i = 0; i < 8; i++){ if (lengthStrFile[i] == '$'){ for (j = 0; j < i;j++){ num = num * 10 + ((const char)lengthStrFile[i] - '0'); } break; } } 
  • 2
    First error: the result of CreateFile is not checked. The second error is a read into an uninitialized pointer lengthStrFile, which also points to an unallocated buffer (that is, it is not known where). I suspect that the third error is that you are not reading the compiler messages. - Vladimir Martyanov
  • Read about GetLastError, and write it down - betrayer

0