Subject: small linux/c++ question.

From: Krzysztof Radacki <[email-masked]>
Date: Wed, 13 Mar 2002 11:43:08 +0000

Dear CCL'ers
I have a little bit out of topic question.
Currently I'm translating my program from Borland C++ 
to gcc and I can't find a function itoa in gcc (it 
converts integer to string).
I would be quite happy if someone could explaine me how 
to do it in gcc.

MfG
Krzysztof

p.s.
because it's realy out-of-topic maybe better if answer 
would be addressed directly to my e-mail not to ccl.

-- 
Dr. K.Radacki
Department of Chemistry
Catalysis and Advanced Materials Section
Imperial College, London

---

From: "CUI, Guanglei" <[email-masked]>
Date: Wed, 13 Mar 2002 09:54:35 -0500 (EST)

You can use sprintf. 

-- 
Guanglei Cui
Dept. of Chemistry
SUNY at Stony Brook
Stony Brook, NY 11790

---

From: "Mark Thompson" <[email-masked]>
Date: Wed, 13 Mar 2002 07:32:05 -0800

Dear Krzysztof,

I've appended an implementation that I've used in the past.  It creates the
string in inverted order and reverses it at the end.  All the usual caveats
about making sure the argument s[] is big enough apply...

Mark

=================================
Mark Thompson, Ph.D.
Planaria Software
Seattle, WA.
http://www.arguslab.com
=================================

void Itoa (int n, char s[])
{
  int   i, j, c, sign;

  if ((sign = n) < 0) {n = -n;}

  i = 0;

  do
  {
    s[i++] = (n % 10) + '0';
  } while ((n /= 10) > 0);

  if (sign < 0) {s[i++] = '-';}

  s[i] = '\0';

  for (i = 0, j = strlen(s) - 1;  i < j; i++, j--)
  {
    c    = s[i];
    s[i] = s[j];
    s[j] = c;
  }
}

> -----Original Message-----
> From: Computational Chemistry List [mailto:[email-masked]]On
> Behalf Of Krzysztof Radacki
> Sent: Wednesday, March 13, 2002 3:43 AM
> To: CCL
> Subject: CCL:small linux/c++ question.
>
>
> Dear CCL'ers
> -= This is automatically added to each message by mailing script =-
> [email-masked] -- To Everybody  | [email-masked] --
> To Admins
> [email-masked] -- HELP CHEMISTRY or HELP SEARCH
> [email-masked] -- archive search    |    Gopher:
> gopher.ccl.net 70
> Ftp: ftp.ccl.net  |  WWW: http://www.ccl.net/chemistry/   | Jan:
> [email-masked]
>
>
>
>
>
>

---

From: Manoj Pal <[email-masked]>
Date: Wed, 13 Mar 2002 15:10:02 -0500 (EST)

Hi Krzysztof,

You can do it with a couple of lines of code in C/C++:

----------------------------------------------------------
 char string_after_conversion[10000]; //make it big
 int int_to_convert;

 //read an int in int_to_convert

 sprintf(string_after_conversion, "%d", int_to_convert);
----------------------------------------------------------

 printf("%s\n",string_after_conversion); //verify...

bye,
.====================================================================.
|                                |                                   |
|  Manoj Pal                     |   Even a stopped clock tells      |
|  Graduate Student              |   the right time twice a day      |
|  Department of Chemistry       |                                   |
|  University of Michigan        |                                   |
|  Ann Arbor, Michigan           |   http://www.manojpal.cjb.net     |
|  USA                           |   Email: [email-masked]       |
|                                |                                   |
'===================================================================='

On Wed, 13 Mar 2002, Mark Thompson wrote:

> [email-masked] -- To Everybody  | [email-masked] -- To Admins
> [email-masked] -- archive search    |    Gopher: gopher.ccl.net 70
> Ftp: ftp.ccl.net  |  WWW: http://www.ccl.net/chemistry/   | Jan: [email-masked]
>
>
>
>
>