Check terminating null character

This is a discussion on Check terminating null character within the C++ Programming forums, part of the General Programming Boards category; The return value of PathFindExtension is: "Returns the address of the "." that precedes the extension within pPath if an ...

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

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

  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
    758
    Perfect, thank you Bench!
    Compiler MSVC++ 2010 with Code::Blocks.

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, 04:17 PM
  3. Why am I getting these errors??
    By maxthecat in forum Windows Programming
    Replies: 3
    Last Post: 02-03-2006, 12: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

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