Thread: Finding whether UCHAR is empty?

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    25

    Finding whether UCHAR is empty?

    Hello,

    As part of some code I'm writing I have to find whether a UCHAR pub[23] contains any characters, or is empty.

    Code:
    UCHAR empty = "";
    
    strcmp(pub, empty);
    {
          counter--; 
    }

    or

    Code:
    strcmp(pub, "");
    {
          counter--; 
    }
    I think its got something to do with casting, but that's something I haven't learned about yet. In reality I haven't a clue. I tried memcmp but couldn't get it to work either.

    Can anyone point me on the right track?

    Thanks.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    How about
    Code:
    if (strlen(pub)==0) {
    edit: anon's next idea is better, qv
    Last edited by MK27; 04-24-2009 at 10:02 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    It would probably be easier to do

    Code:
    if (pub[0] == '\0')
    In case pub is an extremely long string or you are testing lots of strings and most are not empty.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    A variable can't be "empty." It always contains some value. You need to define what you mean by "empty."
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Registered User
    Join Date
    May 2008
    Posts
    25
    Thanks for the help. I wrote the code wrong in my post though.

    I've cut a lot of the code out to simplify things, but what happens is:

    Structure data read into contains:
    Code:
    UCHAR PublisherIdentifier[128];
    Code:
    void read()
    {
    
        reads data from dvd disc.
    
        calculate(*publisher)
    }

    Code:
    void publisher(UCHAR publisher)
    {
            if(publisher == '\0')
            {
                perform action
            }
    
    }

    I get the error "invalid conversion from 'const char*' to 'UCHAR'


    Thanks again chaps.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with binary file c++
    By lucky_mutani in forum C++ Programming
    Replies: 4
    Last Post: 06-05-2009, 09:24 AM
  2. Using uchar for uint8?
    By Witchfinder in forum C Programming
    Replies: 7
    Last Post: 04-20-2009, 12:51 PM
  3. SCSI read disc structure C++ help
    By Witchfinder in forum C++ Programming
    Replies: 0
    Last Post: 03-25-2009, 04:24 PM
  4. finding size of empty char array
    By darsunt in forum C Programming
    Replies: 12
    Last Post: 05-30-2006, 07:23 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM