Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > convert string to integer

Reply
Thread Tools

convert string to integer

 
 
shanmugaster@gmail.com
Guest
Posts: n/a
 
      09-18-2006
Hi,
I have a string array which may contain 5 digit values or NULL or
just blank spaces. I should print the value of array as an integer.
that is it should print 0 when it encounters NULL and blank spaces.
when i used atoi, values greater than 32767 are converted into negative
values. can some one please help me in this regard.

sample values
55008
55009
NULL

55110
NULL

Thanking u in advance

Star

 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      09-18-2006
In article <(E-Mail Removed) .com>,
<(E-Mail Removed)> wrote:
> I have a string array which may contain 5 digit values


>when i used atoi, values greater than 32767 are converted into negative
>values. can some one please help me in this regard.


That implies that on your system, int is not large enough to hold
some of the values. So don't use int: use long instead. There is
an equivilent to atoi() that is for long instead of it: you should
be able to find it easily.
--
"law -- it's a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)
 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      09-18-2006
Walter Roberson said:

> In article <(E-Mail Removed) .com>,
> <(E-Mail Removed)> wrote:
>> I have a string array which may contain 5 digit values

>
>>when i used atoi, values greater than 32767 are converted into negative
>>values. can some one please help me in this regard.

>
> That implies that on your system, int is not large enough to hold
> some of the values. So don't use int: use long instead. There is
> an equivilent to atoi() that is for long instead of it: you should
> be able to find it easily.


Poor advice, since it will lead him to atol() rather than strtol().

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
rama_archana@yahoo.com
Guest
Posts: n/a
 
      09-18-2006

Hi,

how to reverse a string recursively in place

thank you

 
Reply With Quote
 
rama_archana@yahoo.com
Guest
Posts: n/a
 
      09-18-2006

Hi,

how to reverse a string recursively in place

thank you

 
Reply With Quote
 
Spiros Bousbouras
Guest
Posts: n/a
 
      09-18-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Hi,
>
> how to reverse a string recursively in place
>
> thank you


How about sticking to the topic of this thread ? If
you have another topic in mind you are free to start
a new thread.

 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      09-18-2006
In article <(E-Mail Removed)>,
Richard Heathfield <(E-Mail Removed)> wrote:
>Walter Roberson said:


>> an equivilent to atoi() that is for long instead of it:


>Poor advice, since it will lead him to atol() rather than strtol().


The problem was *defined* in terms of restricted sets of input
for which atol() and strtol() will be equivilent.

strtol() is certainly a better choice in the general case, when
input might vary more than was defined for this situation.
--
Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us. -- Ecclesiastes
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      09-18-2006
(E-Mail Removed) writes:
> how to reverse a string recursively in place


Why do you want to do it recursively? An iterative solution is likely
to be more straightforward and more efficient.

The only reason I can think of for that requirement is that this is a
homework assignment. Is it?

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      09-18-2006
(E-Mail Removed) wrote:
>
> how to reverse a string recursively in place


What a silly idea. I see no purpose to using recursion here.

--
"The most amazing achievement of the computer software industry
is its continuing cancellation of the steady and staggering
gains made by the computer hardware industry..." - Petroski



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Ancient_Hacker
Guest
Posts: n/a
 
      09-18-2006

(E-Mail Removed) wrote:
> Hi,
>
> how to reverse a string recursively in place
>
> thank you


this is likely to be homework, so we won't do it all for you. Here's a
few hints:

Recursion can take you down, down, down the string to the end. At that
point, if you start returning, you'll be encountering the characters in
reverse order. What could you do at that point that would give you a
reversed string?

"C" is a fine language for this kind of exercise. You should be able
to do this in like 5 to 8 lines or so.

 
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
Split string (then) Convert string into Integer news ASP General 2 05-26-2010 11:58 AM
is there a way to AutoParse a string to another type - e.g. if aDate format then date, else if integer than Integer etc ????? Greg Hauptmann Ruby 6 08-06-2008 04:52 PM
Change a string to an integer, report an error if the string does not represent an integer? Randy Kramer Ruby 12 10-25-2007 09:56 PM
Convert a Base32 string to Base10 integer Jon Paskett ASP .Net 1 12-18-2005 01:31 AM
convert scientific integer to normal integer les ander Python 4 10-05-2004 04:26 PM



Advertisments