View Single Post
Old May 24th, 2006, 5:01 AM   #8
bivhitscar
Hobbyist Programmer
 
bivhitscar's Avatar
 
Join Date: Oct 2005
Location: Melbourne, Australia
Posts: 126
Rep Power: 4 bivhitscar is on a distinguished road
Quote:
Originally Posted by Jimbo
somewhat simplified: NULL = 0 = '\0'
Well, that is extremely simplified, because you can't do this:

char *ptr;

if ( ptr == '\0' );

To darksabbath:
If you want to check the value of a pointer, use NULL. If you want to check the value at the address a pointer points to, use '\0'.

In your first example while((*s = *t) != '\0') was correct and that's how I would do it. Jimbo's method is perfectly fine too.


[EDIT]

Though, I will mention that the statement while((*s = *t) != '\0') will overwrite memory before checking the value, which isn't very good practice IMO.

[EDIT v2]

And that's why there is a strncpy(), so while my first edit was valid, it is irrelevant with respect to the strcpy function.

I think I'll stop now...
__________________
it's ironic considerate rarity patron of love higher knowledge engulfs me...
bivhitscar is offline   Reply With Quote