Mail Archives: djgpp/1999/05/09/13:55:15
El día Sun, 09 May 1999 10:25:27 -0400, Martin Ambuhl
<mambuhl AT earthlink DOT net> escribió:
>> In BASIC this would be string$="pic"+ltrim$(rtrim$(val(number%)))+".bmp"
>> but how do I do it in C++?
>
>This extremely ugly BASIC construction should make you appreciate the much
>derided-by-C++-advocates sprintf function:
>
>#include <cstdio>
>char *filename;
>int i;
> sprintf(filename,"pic%d.bmp",i);
Yes, but declare filename as an array of char or else malloc the
memory you need. Declaring a pointer an then just writing to it
doesn't seem to be a good idea.
I would suggest:
char filename[FILENAME_MAX];
because FILENAME_MAX is defined by ANSI-C to be the maximum length
needed to store the name of a file.
Regards,
GUILLE
----
Guillermo Rodriguez Garcia
XXguille AT XXiies DOT XXes (ya sabes :-)
- Raw text -