Fw: [Dev-C++] string conversion to integer
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Sam <sch...@ho...> - 2001-01-20 18:35:54
|
Just reread your original message......i'm not sure if these functions of
the conversion specifier works with objects.
Sorry if the response wasn't exactly on target.
> ----- Original Message -----
> From: Sam <sch...@ho...>
> To: <dev...@li...>
> Sent: Saturday, January 20, 2001 1:33 PM
> Subject: Re: [Dev-C++] string conversion to integer
>
>
> > It is my understanding that atoi converts its argument, the whole
string.
> > However, to convert a part of a string(a sequence of characters) you
would
> > have to use strtod or strtol. All of these functions convert strings of
> > DIGITS to integers, doubles, floats etc.
> >
> > The strod function receives two arguments, 1. a string and 2. a pointer
to
> a
> > string.
> >
> > The strol function receives three arguments 1. a string, 2. a pointer to
a
> > string, and an integer which signifies the base of the value to be
> > converted.
> >
> > If you are trying to convert a character such as A just use the %d
> > conversion specifier.
> >
> > i.e.
> >
> > char string[] = "grapes";
> >
> > printf("%s\n", string);
> > printf("%d\n\n", string[3]);
> >
> >
> > output looks like:
> >
> > grapes
> > 112
> >
> > Hope this helps.
> > Sam
> >
> > ----- Original Message -----
> > From: Alan Thomas <ala...@3n...>
> > To: <dev...@li...>
> > Sent: Saturday, January 20, 2001 11:27 AM
> > Subject: [Dev-C++] string conversion to integer
> >
> >
> > > I thought I knew how to convert string objects to integer. I
> > > thought a character (e.g., input_string[2] of object string
> input_string)
> > > could be referenced in a string and converted using the C
> ASCII-to-integer
> > > function atoi. However, the compiler doesn`t like that and apparently
> > does
> > > not see an element of a string array as a character.
> > >
> > > How do you do this? Thanks, Alan
> > >
> > >
> > >
> > >
> > > _______________________________________________
> > > Dev-cpp-users mailing list
> > > Dev...@li...
> > > http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > >
> >
>
|