www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/09/13:55:15

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: <HhOCsDAf$YN3EwuI AT dunvegan1 DOT demon DOT co DOT uk> <37359AD7 DOT 8FC41504 AT earthlink DOT net>
NNTP-Posting-Host: iies229.iies.es
Mime-Version: 1.0
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
<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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019