Subject: Re: snprintf() problem or I am stupid C programmer
To: Ciarcinski, Adam \(ISS Brussels\) <ACiarcinski@iss.net>
From: Andrew Brown <email@example.com>
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" >-----|
firstname.lastname@example.org * "ah! i see you have the internet
email@example.com (Andrew Brown) that goes *ping*!"
firstname.lastname@example.org * "information is power -- share the wealth."