Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > string to int

Reply
Thread Tools

string to int

 
 
shan
Guest
Posts: n/a
 
      12-10-2005
Hi to all,
Is there any way to convert string to integer.string will
contain only integers.I am using turbo c++
example :
"321" to 321

 
Reply With Quote
 
 
 
 
Chris McDonald
Guest
Posts: n/a
 
      12-10-2005
"shan" <(E-Mail Removed)> writes:

>Hi to all,
> Is there any way to convert string to integer.string will
>contain only integers.I am using turbo c++
>example :
> "321" to 321



int i = atoi("321");

--
Chris.
 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      12-10-2005
Chris McDonald wrote:
> "shan" <(E-Mail Removed)> writes:


> > Is there any way to convert string to integer.string will
> >contain only integers.I am using turbo c++
> >example :
> > "321" to 321

>
> int i = atoi("321");


strtol() would be better, atoi() has poor error handling


--
Nick Keighley

 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      12-10-2005
Chris McDonald wrote:
>
> "shan" <(E-Mail Removed)> writes:
>
> >Hi to all,
> > Is there any way to convert string to integer.string will
> >contain only integers.I am using turbo c++
> >example :
> > "321" to 321


#include <stdlib.h>

> int i = atoi("321");


--
pete
 
Reply With Quote
 
John Bode
Guest
Posts: n/a
 
      12-10-2005

shan wrote:
> Hi to all,
> Is there any way to convert string to integer.string will
> contain only integers.I am using turbo c++
> example :
> "321" to 321


#include <stdlib.h>
#include <ctype.h>
....
char *chk;
int val = (int) strtol("321", &chk, 10);
if (!isspace((int) *chk) && *chk != 0)
{
/* input string contains invalid character */
}

 
Reply With Quote
 
Robert Gamble
Guest
Posts: n/a
 
      12-10-2005
John Bode wrote:
> shan wrote:
> > Hi to all,
> > Is there any way to convert string to integer.string will
> > contain only integers.I am using turbo c++
> > example :
> > "321" to 321

>
> #include <stdlib.h>
> #include <ctype.h>
> ...
> char *chk;
> int val = (int) strtol("321", &chk, 10);


The cast produces implementation-defined behavior if the return value
of strtol exceeds the representable range of int. Jack Klein has
written a very robust example of how to do this correctly at
http://home.att.net/~jackklein/c/code/strtol.html.

Robert Gamble

 
Reply With Quote
 
Stan Milam
Guest
Posts: n/a
 
      12-11-2005
shan wrote:
> Hi to all,
> Is there any way to convert string to integer.string will
> contain only integers.I am using turbo c++
> example :
> "321" to 321
>


atoi(), or strtod(), or even sscanf().
 
Reply With Quote
 
Joe Wright
Guest
Posts: n/a
 
      12-11-2005
Stan Milam wrote:
> shan wrote:
>
>> Hi to all,
>> Is there any way to convert string to integer.string will
>> contain only integers.I am using turbo c++
>> example :
>> "321" to 321
>>

>
> atoi(), or strtod(), or even sscanf().


That would be strtol(), surely.
--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
 
Reply With Quote
 
SM Ryan
Guest
Posts: n/a
 
      12-12-2005
"shan" <(E-Mail Removed)> wrote:
# Hi to all,
# Is there any way to convert string to integer.string will
# contain only integers.I am using turbo c++
# example :
# "321" to 321

strtol and related routines, or sscanf.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
The little stoner's got a point.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
map question - need to find a string from an int but also need the int from the string? Angus C++ 3 05-03-2008 02:27 PM
Difference between int i, j; and int i; int j; arun C Programming 8 07-31-2006 05:11 AM
int a[10]; int* p=(int*)((&a)+1); But why p isn't equal to ((&a)+1)? aling C++ 8 10-20-2005 02:42 PM
int main(int argc, char *argv[] ) vs int main(int argc, char **argv ) Hal Styli C Programming 14 01-20-2004 10:00 PM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM



Advertisments