strcmp() Always Returns True.

Hi Guys!

I have the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <windows.h>
#include <cstdlib>
#include <cstdio>

int main()
{
    const std::size_t BUFF_SZ = 255;

        char value[BUFF_SZ]{};
        DWORD buff_sz = sizeof(value); // size of the buffer
        RegGetValueA(HKEY_LOCAL_MACHINE, "Registry Key Here", "TEST",
            RRF_RT_REG_SZ, nullptr, value, &buff_sz);

        printf(value);


        int result = strcmp(value, "DOUBLE");
        if (result == 0) {
            printf("Strings are equal");
        }
        else {
            printf("Strings are unequal");
        }
        Sleep(5000);
   
}


Now, it keeps responding true, even if the results do not match. Any ideas on what I am doing wrong??

Many Thanks,

Googie.
print exactly what is in value, in hex, every character... there is probably some hard to see difference.

you can also check the error code status to see if the reg-get-value thing failed. if it fails, it may leave the old value in memory... seems like an odd thing to happen since you clear it with {} though. I don't see a code problem at all. Are you running it, then changing registry, then running again? Any chance something was cached or something didn't register the change..?
Last edited on
Topic archived. No new replies allowed.