this example gets a random number (an integer) and prints the first 5
characters in your fixed size string.
temember that you need an extra character to allow for null
termination.hence randString[6] instead of randString[5].
Bruno:
Shouldn't that be
sprintf(randString, "%05d", i);
David Wilkinson
you are partially right. there is still a second problem with my example :-)
doing it like this assures only that there are minimum 5 characters, all of
which will have
a numerical value between 0 and 9.
if i has more than 5 decimal digits it would try to print out all characters
with a buffer overflow as the result.
to do it correct you have to make sure that i is never more than 5 digits.
the correct solution in that case is this:
sprintf(randString, "%05d", i%100000);
That'll teach me to post an example without testing it first ... :-)
--
Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"