Groups > Borland > Borland C plus plus builder command line tools > Re: strcmp doesn't accept NULL argument




Re: strcmp doesn't accept NULL argument

Re: strcmp doesn't accept NULL argument
Thu, 21 Feb 2008 17:57:42 -050
strcmp has always been defined in the language specs as not being safe with 
a NULL argument.

If you must use a NULL argument then use the Windows function lstrcmp.

.  Ed

> Maurice wrote in message
> news:47bdd5f8@newsgroups.borland.com...
>
> I noticed that with version 5.5 "strcmp" doesn't accept argument
if it is 
> NULL, it report error problem, is there another equivalent function??
>
> the following program cause error if launched without any argument, if 
> compiled with version 5.2 or older, it works
>
> Thanks
> Maurice
>
> ////////////////////////////////////////////////////////////////////
> #include "stdio.h"
> #include "string.h"
>
> main(int argc, char *argv[])
> {
> if(!strcmp(argv[1],"hello")) printf(" hi\n");
> else printf("bye\n");
> }
>
> ////////////////////////////////////////////////////////////////////

Post Reply
strcmp doesn't accept NULL argument
Thu, 21 Feb 2008 21:48:24 +020
Hello:

I noticed that with version 5.5 "strcmp" doesn't accept argument if it
is 
NULL, it report error problem, is there another equivalent function??

the following program cause error if launched without any argument, if 
compiled with version 5.2 or older, it works

Thanks
Maurice

////////////////////////////////////////////////////////////////////
#include "stdio.h"
#include "string.h"

main(int argc, char *argv[])
{
if(!strcmp(argv[1],"hello")) printf(" hi\n");
else printf("bye\n");
}

////////////////////////////////////////////////////////////////////


Post Reply
Re: strcmp doesn't accept NULL argument
Thu, 21 Feb 2008 23:23:06 +010
"Maurice" <morisaab@yahoo.fr> writes:

> I noticed that with version 5.5 "strcmp" doesn't accept argument
if
> it is NULL, it report error problem,

Correct. invoking strcmp() with one or two NULL pointers causes the
program to have undefined behavior.


> is there another equivalent function??

Well, you can always write one of your own.


> the following program cause error if launched without any argument, if 
> compiled with version 5.2 or older, it works
>
> Thanks
> Maurice
>
> ////////////////////////////////////////////////////////////////////
> #include "stdio.h"
> #include "string.h"
>
> main(int argc, char *argv[])
> {
> if(!strcmp(argv[1],"hello")) printf(" hi\n");
> else printf("bye\n");
> }

Post Reply
Re: strcmp doesn't accept NULL argument
Sat, 23 Feb 2008 12:01:11 +020
"Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> wrote in message
news:47be01ea$1@newsgroups.borland.com...
> strcmp has always been defined in the language specs as not being safe
> with a NULL argument.
>
> If you must use a NULL argument then use the Windows function lstrcmp.
>
> .  Ed
>

Thank you
Maurice


Post Reply
about | contact