From: XXguille AT XXiies DOT XXes (Guillermo Rodriguez Garcia) Newsgroups: comp.os.msdos.djgpp Subject: Re: Converting numbers to strings Date: Sun, 09 May 1999 17:25:57 GMT Organization: Telefonica Transmision de Datos Lines: 31 Message-ID: <3735c49e.1549672@noticias.iies.es> References: <37359AD7 DOT 8FC41504 AT earthlink DOT net> NNTP-Posting-Host: iies229.iies.es Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Newsreader: Forte Agent 1.5/32.451 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com El día Sun, 09 May 1999 10:25:27 -0400, Martin Ambuhl 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 >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 :-)