strcmp returns always 0

This is a discussion on strcmp returns always 0 within the C Programming forums, part of the General Programming Boards category; I dont understand, it always enters if(). Code: #include <windows.h> #include <iostream> using namespace std; char WindowTitle[MAX_PATH]; BOOL CALLBACK Enum(HWND ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Location
    France
    Posts
    749

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

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

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Location
    France
    Posts
    749
    lol damn it? too easy.
    Thanks! :-)
    Compiler MSVC++ 2010 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, 10: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, 06: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

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