[snip]
/* Make sure you have enough room in your result char array. */
char result[100];
Shouldn't this bear some resemblance to the maximum length of
a filename on the machine and any bizarre semantics about the
characters in the filename? (8.3 perhaps).
int filenumber = 10;
sprintf( result, "%s%d.txt", "filename", filenumber );
How do you check to make sure there is room? In a real implementation,
"filename" might be
"whatevertheuserhappenedtoenterwhenpromptedforafilenamejustbecauseicankeep
ontypinguntilIgetboredormypizzaisreadytotakeoutoftheoven"
depending on how the input is collected. That, plus some number, like
INT_MAX might make for a nice overflow with the above.
OTOH, if you know as the OP indicated that it will always be "test"%d,
you need only be sure that the strlen of "filenumber" (as a string) +
"test" + ".txt" + 1 isn't longer than result and that it does not violate
the filename conventions on the platform.
--
Randy Howard _o
2reply remove FOOBAR \<,
______________________()/ ()______________________________________________
SCO Spam-magnet: (e-mail address removed)