473,386 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

strcmp Producing NullReferenceException

iknc4miles
Hey everyone,

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

System.NullReferenceException: 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

Expand|Select|Wrap|Line Numbers
  1. try
  2. {
  3.      char* svr_type;
  4.      svr_type = getNextWord(&str);
  5.  
  6.      if( strcmp(svr_type, "ALG") == 0)
  7.      {
  8.          // Does Algorithm server already exist?
  9.      }
  10.      else if(strcmp(svr_type, "ENV") == 0)
  11.      {
  12.          // Does Environment server already exist?
  13.      }
  14.  
  15.  }
  16.  catch(NullReferenceException *e)
  17.  {
  18.      tbLog->AppendText(e->ToString());
  19.      return;
  20.  }
Mar 6 '07 #1
1 2095
horace1
1,510 Expert 1GB
try printing out the string pointed at to check what you are getting?
Expand|Select|Wrap|Line Numbers
  1.      char* svr_type;
  2.      svr_type = getNextWord(&str);
  3.          printf("%s\n", svr_type);
  4.  
  5. ..
  6.  
Mar 6 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in...
6
by: muser | last post by:
The following error appears: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char *'. I've already tried using single quotations. the header file only contains the struct contents....
11
by: Eirik | last post by:
Shouldn't this code work? If not, why shouldn't it? #include <stdio.h> int main(void) { char yesno; char *yes = "yes";
2
by: Raed Sawalha | last post by:
i have a windows form(Main) with listview, when click an item in listview i open other window form (Sub) which generate the selected item from parent window in as treeview items when click any item...
9
by: Steven | last post by:
Hello, I have a question about strcmp(). I have four words, who need to be compared if it were two strings. I tried adding the comparison values like '(strcmp(w1, w2) + strcmp(w3, w4))', where...
36
by: Chuck Faranda | last post by:
I'm trying to debug my first C program (firmware for PIC MCU). The problem is getting serial data back from my device. My get commands have to be sent twice for the PIC to respond properly with...
0
by: noobcprogrammer | last post by:
#include "IndexADT.h" int IndexInit(IndexADT* word) { word->head = NULL; word->wordCount = 0; return 1; } int IndexCreate(IndexADT* wordList,char* argv)
47
by: fishpond | last post by:
One way I've seen strcmp(char *s1, char *s2) implemented is: return immediately if s1==s2 (equality of pointers); otherwise do the usual thing of searching through the memory at s1 and s2. Of...
2
by: thungmail | last post by:
There is partial code in C typedef struct message { int messageId; char *messageText; struct message *next; }message; ..... ..... ..... /* Get a node before a node */
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.