Thread: Check terminating null character

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

    Check terminating null character

    The return value of PathFindExtension is:

    "Returns the address of the "." that precedes the extension within pPath if an extension is found, or the address of the terminating null character otherwise."

    How to check against the terminating null character?
    It never enters if().

    Code:
    int main()
    {
        char * str = "";
    
        if((str = PathFindExtension( "C:\\filetxt" )) == '\0')
            cout<< "Error" << endl;
        else
            cout<< str << endl;
    
        return 0;
    }
    Using Windows 10 with Code Blocks and MingW.

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Since you're using C++, you could use a string

    Code:
    #include <iostream>
    #include <string>
    
    int main()
    {
        std::string str = PathFindExtension("C:\\filetxt");
        if( str == "" )
            std::cout << "Error" << std::end;
        else
            std::cout << str << std::endl;
    }
    If you simply want to look at the character rather than the string itself
    Code:
    char* str = PathFindExtension( "C:\\filetxt" );
    if(str[0] == '\0')
        std::cout << "Error";

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    Perfect, thank you Bench!
    Using Windows 10 with Code Blocks and MingW.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "Virtual Printer" or "Moving Printjobs"
    By extasic in forum Windows Programming
    Replies: 12
    Last Post: 06-30-2011, 08:33 AM
  2. IDE for C embedded advanced editing
    By Undici77 in forum Tech Board
    Replies: 32
    Last Post: 01-16-2010, 05:17 PM
  3. Why am I getting these errors??
    By maxthecat in forum Windows Programming
    Replies: 3
    Last Post: 02-03-2006, 01:00 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM