445,778 Members | 1,997 Online
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

# string to int

 P: n/a 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 Dec 10 '05 #1
8 Replies

 P: n/a "shan" writes: Hi to all, Is there any way to convert string to integer.string willcontain only integers.I am using turbo c++example : "321" to 321 int i = atoi("321"); -- Chris. Dec 10 '05 #2

 P: n/a Chris McDonald wrote: "shan" writes: Is there any way to convert string to integer.string willcontain 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 Dec 10 '05 #3

 P: n/a Chris McDonald wrote: "shan" writes:Hi to all, Is there any way to convert string to integer.string willcontain only integers.I am using turbo c++example : "321" to 321 #include int i = atoi("321"); -- pete Dec 10 '05 #4

 P: n/a 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 #include .... char *chk; int val = (int) strtol("321", &chk, 10); if (!isspace((int) *chk) && *chk != 0) { /* input string contains invalid character */ } Dec 10 '05 #5

 P: n/a 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 #include ... 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 Dec 10 '05 #6

 P: n/a 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(). Dec 11 '05 #7

 P: n/a 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 --- Dec 12 '05 #8

 P: n/a "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 strtol and related routines, or sscanf. -- SM Ryan http://www.rawbw.com/~wyrmwif/ The little stoner's got a point. Dec 12 '05 #9

### This discussion thread is closed

Replies have been disabled for this discussion.