Subject: Re: snprintf() problem or I am stupid C programmer
To: Ciarcinski, Adam \(ISS Brussels\) <ACiarcinski@iss.net>
From: Andrew Brown <firstname.lastname@example.org>
Date: 07/17/2001 15:39:24
>char *test = "Test";
>snprintf(test, 5, "Passed");
>If you compile and run it - crash!
the wasy this is written, test is allocated as a char pointer on the
stack that points to a static (read-only) string. you can printf()
it, but not snprintf() into it (write into it).
>If you change 'char *test' to 'char test' - works!
test in this case is allocated as a char array of length 5 on the
stack which is writeable.
|-----< "CODE WARRIOR" >-----|
email@example.com * "ah! i see you have the internet
firstname.lastname@example.org (Andrew Brown) that goes *ping*!"
email@example.com * "information is power -- share the wealth."