Thread: strcmp returns always 0

  1. #1
    Registered User
    Join Date
    Dec 2007

    strcmp returns always 0

    I dont understand, it always enters if().

    #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);
    Compiler MSVC++ 2013 with Code::Blocks.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    United States
    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
    The edge of the known universe
    > 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
    lol damn it? too easy.
    Thanks! :-)
    Compiler MSVC++ 2013 with Code::Blocks.

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
    Replies: 2
    Last Post: 06-15-2005, 09:53 AM