Dear Randy
Thanks for your answer. As you said, my pointer was a NULL pointer. So I
correct the code as follows:
const char *x="Reza";
if (rq->rq_anon != NULL)
{
if (strcmp(rq->rq_anon,x) == 0)
{
//Do something
}
}
Best Regards,
______________________________________________________
Reza Karimi, M.Sc.
Faculty of Electrical and Computer Engineering (ECE)
K.N.Toosi University of Technology
Tehran, IRAN.
-----Original Message-----
From: Turner, Randy [mailto:[email protected]]
Sent: Monday, June 09, 2014 6:23 PM
To: Reza Karimi; [email protected]
Subject: RE: [ns] Problem with const char*
It's possible that the "rq_anon" pointer is either pointing to an invalid
memory location, OR the string pointed to by rq_anon is not null-terminated
Randy
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf
Of Reza Karimi
Sent: Sunday, June 08, 2014 1:27 PM
To: [email protected]
Subject: [ns] Problem with const char*
Hi
Please take a look at the following code:
---------------------------------------
const char *x="Reza";
if (strcmp(rq->rq_anon,x) == 0)
{
//Do something
}
--------------------------------------
"rq" is a pointer to the header of RREQ packet and "rq_anon" is a pointer to
const data. This is a part of my routing protocol. Making is OK. The problem
is that when I run my Tcl program related to this routing protocol,
segmentation falut occurs. But when I changed this code to:
---------------------------------------
if (rq->rq_anon == "Reza")
{
//Do something
}
--------------------------------------
it works! with one warning that is expected. So what is the problem? Is it a
bug in NS?
______________________________________________________
Reza Karimi, M.Sc.
Faculty of Electrical and Computer Engineering (ECE)
K.N.Toosi University of Technology
Tehran, IRAN.
P PLEASE CONSIDER OUR ENVIRONMENT BEFORE PRINTING THIS EMAIL.
This e-mail (including any attachments) is confidential and may be legally
privileged. If you are not an intended recipient or an authorized
representative of an intended recipient, you are prohibited from using,
copying or distributing the information in this e-mail or its attachments.
If you have received this e-mail in error, please notify the sender
immediately by return e-mail and delete all copies of this message and any
attachments. Thank you.