Re: CCL:small linux/c++ question.
- From: Manoj Pal <manojp &$at$& umich.edu>
- Subject: Re: CCL:small linux/c++ question.
- 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: pal_m &$at$& mailcity.com |
| | |
'===================================================================='
On Wed, 13 Mar 2002, Mark Thompson wrote:
>
> 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:chemistry-request &$at$& ccl.net]On
> > Behalf Of Krzysztof Radacki
> > Sent: Wednesday, March 13, 2002 3:43 AM
> > To: CCL
> > Subject: CCL:small linux/c++ question.
> >
> >
> > 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
> >
> > CHEMISTRY &$at$& ccl.net -- To Everybody | CHEMISTRY-REQUEST &$at$&
ccl.net --
> > To Admins
> > CHEMISTRY-SEARCH &$at$& ccl.net -- archive search | Gopher:
> > gopher.ccl.net 70
> > Ftp: ftp.ccl.net | WWW: http://www.ccl.net/chemistry/ | Jan:
> > jkl &$at$& ccl.net
> >
> >
> >
> >
> >
> >
>
>
> -= This is automatically added to each message by mailing script =-
> CHEMISTRY &$at$& ccl.net -- To Everybody | CHEMISTRY-REQUEST &$at$&
ccl.net -- To Admins
> MAILSERV &$at$& ccl.net -- HELP CHEMISTRY or HELP SEARCH
> CHEMISTRY-SEARCH &$at$& ccl.net -- archive search | Gopher:
gopher.ccl.net 70
> Ftp: ftp.ccl.net | WWW: http://www.ccl.net/chemistry/ | Jan: jkl &$at$& ccl.net
>
>
>
>
>