Thread: strcmp returns always 0

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    930

    strcmp returns always 0

    I dont understand, it always enters if().

    Code:
    #include <windows.h>
    #include <iostream>
    using namespace std;
    char WindowTitle[MAX_PATH];
    
    BOOL CALLBACK Enum(HWND hwnd, LPARAM lParam)
    {
            GetWindowText(hwnd, WindowTitle, 260);
            cout<<"1. "<<WindowTitle<<endl;
    
            if(!strcmp(WindowTitle, "Calculator"));
            {
                cout<<"2. "<<WindowTitle<<endl;
            }
    
        return TRUE;
    }
    
    int main()
    {
        EnumWindows(&Enum, 0);
    }
    Using Windows 10 with Code Blocks and MingW.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    So, to make this interesting, are you saying the window title isn't Calculator?

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > if(!strcmp(WindowTitle, "Calculator"));
    Programming for 5 years, and still being caught out by the trailing ; huh?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    930
    lol damn it? too easy.
    Thanks! :-)
    Using Windows 10 with Code Blocks and MingW.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DialogBox returns -1. GetLastError returns error 1813.
    By Benji Wiebe in forum Windows Programming
    Replies: 14
    Last Post: 09-26-2011, 10:21 AM
  2. what exactly does strcmp() do?
    By MattJ812 in forum C++ Programming
    Replies: 6
    Last Post: 01-16-2011, 11:02 PM
  3. strcmp
    By bob1223 in forum C Programming
    Replies: 4
    Last Post: 08-29-2010, 08:24 AM
  4. Operator that returns no value but returns value
    By keira in forum C++ Programming
    Replies: 3
    Last Post: 01-19-2008, 07:22 PM
  5. main returns int -- compiler returns nonsense
    By Zach L. in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 06-15-2005, 09:53 AM