strcmp Producing NullReferenceException

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • iknc4miles
    New Member
    • Oct 2006
    • 32

    strcmp Producing NullReferenceException

    Hey everyone,

    Below I try to use strcmp to compare svr_type to a constant string array. Occasionally this produces a NullReferenceEx ception. I put in a try catch just so I could get the full error and this is what I got:

    System.NullRefe renceException: Object reference not set to an instance of an object.
    at strcmp(SByte* , SByte* )

    I'm not entirely sure why. getNextWord modifies the input string and returns a pointer to a new char[30] so the memory must be allocated.

    Any ideas?

    - iknc4miles

    Code:
    try
    {
    	 char* svr_type;
    	 svr_type = getNextWord(&str);
    
    	 if( strcmp(svr_type, "ALG") == 0)
    	 {
    		 // Does Algorithm server already exist?
    	 }
    	 else if(strcmp(svr_type, "ENV") == 0)
    	 {
    		 // Does Environment server already exist?
    	 }
    			 
     }
     catch(NullReferenceException *e)
     {
    	 tbLog->AppendText(e->ToString());
    	 return;
     }
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    try printing out the string pointed at to check what you are getting?
    Code:
    	 char* svr_type;
    	 svr_type = getNextWord(&str);
             printf("%s\n", svr_type);
    
    ..

    Comment

    Working...