Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: '\0' ?

Reply
Thread Tools

Re: '\0' ?

 
 
Skybuck Flying
Guest
Posts: n/a
 
      11-01-2004

"Skybuck Flying" <(E-Mail Removed)> wrote in message news:...
> > >
> > >
> > > #include <string.h>
> > > #include <memcopy.h>
> > >
> > > #undef strcmp
> > >
> > > /* Compare S1 and S2, returning less than, equal to or
> > > greater than zero if S1 is lexicographically less than,
> > > equal to or greater than S2. */
> > > int
> > > strcmp (p1, p2)
> > > const char *p1;
> > > const char *p2;
> > > {
> > > register const unsigned char *s1 = (const unsigned char *) p1;
> > > register const unsigned char *s2 = (const unsigned char *) p2;
> > > unsigned reg_char c1, c2;
> > >
> > > do
> > > {
> > > c1 = (unsigned char) *s1++;
> > > c2 = (unsigned char) *s2++;
> > > if (c1 == '\0')
> > > return c1 - c2;

> >
> > if stored in s1 is '\0' then c1 would equal 0. c2 may be some
> > unsigned value, for example, 97.
> > So you have, for example, (unsigned)0 - (unsigned)97. Is is
> > possible or not possilbe for this to return a negative value
> > when converted to type int and returned from the function?

>
> Good question.
>
> In delphi it returns a negative value which is ok.
>
> In visual C/C++ 6.0 it returns a positive value which is probably wrong

<-
> ouch.


God I suck at C lol.. my example was wrong... It does return -97

int bla()
{
unsigned char a;
unsigned char b;

a = 0;
b = 97;

return (a-b);

}

int main()
{

printf("bla: %d \n", bla() );

if (bla() == -97)

printf("ok\n");
}

Bye,
Skybuck.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments