re:return a string



(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++

.



Relevant Pages

  • Re: change array size at runtime
    ... Static arrays can't be resized. ... The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html The C-library: http://www.dinkumware.com/refxc.html ... "You are sentenced to 30 lashes with a wet noodle." ...
    (comp.lang.c)
  • Re: C book recommendations
    ... you can go beyond what the standard imposes ... The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html The C-library: http://www.dinkumware.com/refxc.html ... "You are sentenced to 30 lashes with a wet noodle." ...
    (comp.lang.c)
  • Re: C Program [ Turbo-C ] , to extract only-Printable-characters from a file ( any type
    ... don't forget fclose() when finished... ... The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html The C-library: http://www.dinkumware.com/refxc.html ... "You are sentenced to 30 lashes with a wet noodle." ...
    (comp.lang.c)
  • Re: Coding embedded systems with C
    ... James wrote on 26/07/05: ... The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html The C-library: http://www.dinkumware.com/refxc.html ... "You are sentenced to 30 lashes with a wet noodle." ...
    (comp.lang.c)
  • Re: memset
    ... Walter Roberson wrote on 26/04/05: ... The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html The C-library: http://www.dinkumware.com/refxc.html ... "You are sentenced to 30 lashes with a wet noodle." ...
    (comp.lang.c)