'\0' ?
From: Skybuck Flying (nospam_at_hotmail.com)
Date: 10/31/04
- Next message: Barry Schwarz: "Re: Usage of scanf to prevent buffer overflow..."
- Previous message: Jens.Toerring_at_physik.fu-berlin.de: "Re: Newbie Program That Started Off Easy - Simple Math w/ Interactive Menu"
- Next in thread: Steve Graegert: "Re: '\0' ?"
- Reply: Steve Graegert: "Re: '\0' ?"
- Reply: Al Bowers: "Re: '\0' ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 31 Oct 2004 14:25:24 +0100
Hi,
I have a question about \0
This is the implementation of strcmp in glibc.
Which is probably the same on many other compilers/libraries.
My question is about this:
if (c1 == '\0')
What does '\0' mean ?
Is that a null terminated character ?
Does that mean strcmp stops comparing as soon as it encounters a null
terminated character ?
#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;
}
while (c1 == c2);
return c1 - c2;
}
libc_hidden_builtin_def (strcmp)
Bye,
Skybuck.
- Next message: Barry Schwarz: "Re: Usage of scanf to prevent buffer overflow..."
- Previous message: Jens.Toerring_at_physik.fu-berlin.de: "Re: Newbie Program That Started Off Easy - Simple Math w/ Interactive Menu"
- Next in thread: Steve Graegert: "Re: '\0' ?"
- Reply: Steve Graegert: "Re: '\0' ?"
- Reply: Al Bowers: "Re: '\0' ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]