What's wrong?

This is a discussion on What's wrong? within the Windows Programming forums, part of the Platform Specific Boards category; I have a windows dialog prog using msvc++. the dialog has a button on with the text "ok" (without the ...

  1. #1
    unregged
    Guest

    What's wrong?

    I have a windows dialog prog using msvc++. the dialog has a button on with the text "ok" (without the quotes) - problem below:-
    Code:
    char ok[10];
    
    case IDOK:
    GetDlgItemText(hWnd, IDOK, ok, sizeof(ok));
    
    if (ok == "ok")
    {
    MessageBox(hWnd, "BOO", "BOO", MB_OK);
    }
    break;
    Why does'nt the message box show?

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    You cant use the "==" operator on char arrays like that...

    include string.h and do this

    Code:
    char ok[10];
    
    case IDOK:
    GetDlgItemText(hWnd, IDOK, ok, sizeof(ok));
    
    if (!strcmp(ok,"ok"))
    {
    MessageBox(hWnd, "BOO", "BOO", MB_OK);
    }
    break;

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    !strcmp(ok,"ok") is valid, but it would be more correct to print (strcmp(ok,"ok") == 0).
    The first could easily be read "if the strings ok and "ok" doesn't compare".
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by Magos
    !strcmp(ok,"ok") is valid, but it would be more correct to print (strcmp(ok,"ok") == 0).
    The first could easily be read "if the strings ok and "ok" doesn't compare".
    :: Cracks whip..."Back Magos,..back damn you!!!" ::



    Yeah I suppose the (... = 0) is easier to understand....but I kind of like the (!..) thing......ah well!


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 04:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 01:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 02:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21