can i find unsigned char buffer[50] is null or not?

Discussion in 'Mac Programming' started by mkristain, Aug 30, 2011.

  1. mkristain macrumors regular

    Joined:
    Aug 18, 2011
    #1
    hi is there any option to find unsigned char buffer[50] having all null values or not.

    thanks.
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    Code:
    unsigned char allNull[50] = {'\0'};
    if(memcmp(allNull,buffer,50) == 0) {
      printf("buffer is all null");
    }
    
    -Lee
     
  3. camjknight macrumors newbie

    Joined:
    Nov 7, 2007
    #3
    Here's a simple function.

    Code:
    bool allNull(char * string, int length) {
    	for (int i = 0; i < length; ++i) {
    		if (string[i] != NULL) return false;
    	}
    	
    	return true;
    }
    
     
  4. mkristain thread starter macrumors regular

    Joined:
    Aug 18, 2011

Share This Page