re:return a string
- From: "Emmanuel Delahaye" <emdel@xxxxxxxxxxxxxx>
- Date: Sat, 30 Apr 2005 09:07:00 +0200
(supersedes <mn.f21f7d549c42ea38.15512@xxxxxxxxxxxxxx>)
iru_muzgo wrote on 29/04/05 :
void
ptr_tralha(char *s)
{
while (*s != '\0') /* while the contents of s are different * from NULL */
NULL is off-topic here. You meant 0. The probem is, what makes you think that there is a 0 in the area pointed by s ? And even if there is one, what makes you think that it is at the correct position ?
This is a serious design problem...
*s++ = '#'; /* s = '#' . increment s */ }
int main(void) { char s[5];
As you can see, the contain of is undetermined.
ptr_tralha(s);
hence, the behaviour is undefined. Anything could happen...
puts(s); return 0; }
-- Emmanuel The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html The C-library: http://www.dinkumware.com/refxc.html
"Clearly your code does not meet the original spec." "You are sentenced to 30 lashes with a wet noodle." -- Jerry Coffin in a.l.c.c++
.
- Follow-Ups:
- Re: return a string
- From: Keith Thompson
- Re: return a string
- References:
- re:return a string
- From: iru_muzgo
- re:return a string
- Prev by Date: Re: two dimensional arrays:
- Next by Date: Re: How is strlen implemented?
- Previous by thread: Re: return a string
- Next by thread: Re: return a string
- Index(es):
Relevant Pages
|