473,471 Members | 1,981 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

convert string to integer

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

Sep 18 '06 #1
11 2292
In article <11**********************@h48g2000cwc.googlegroups .com>,
<sh**********@gmail.comwrote:
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)
Sep 18 '06 #2
Walter Roberson said:
In article <11**********************@h48g2000cwc.googlegroups .com>,
<sh**********@gmail.comwrote:
> 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)
Sep 18 '06 #3

Hi,

how to reverse a string recursively in place

thank you

Sep 18 '06 #4

Hi,

how to reverse a string recursively in place

thank you

Sep 18 '06 #5
ra**********@yahoo.com 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.

Sep 18 '06 #6
In article <BL******************************@bt.com>,
Richard Heathfield <in*****@invalid.invalidwrote:
>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
Sep 18 '06 #7
ra**********@yahoo.com 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) ks***@mib.org <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.
Sep 18 '06 #8
ra**********@yahoo.com 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

Sep 18 '06 #9

ra**********@yahoo.com 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.

Sep 18 '06 #10
Walter Roberson said:
In article <BL******************************@bt.com>,
Richard Heathfield <in*****@invalid.invalidwrote:
>>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.
You do have a point but, as the the OP pointed out, the input data may
contain NULL (by which I guess he means the empty string) or "just blank
spaces". The strtol function will enable these cases to be detected,
whereas atol will IIRC simply return 0.

Now, it's certainly true that he said he just wanted these to be interpreted
as 0, which I missed, and which is why you have a point. But when he
discovers how simple it is to detect them, he may prefer to take advantage
of the extra functionality that strtol() offers.

Shall we call this one 70-30 in your favour? :-)

--
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)
Sep 18 '06 #11
ra**********@yahoo.com wrote:
>
Hi,
Don't hijack threads. You posted this in reply to "convert string to
integer". Go figure you how to use Google to start a new thread.


Brian
Sep 18 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: IamZadok | last post by:
Hi I was wondering if anyone knew how to convert a string or an integer into a Static Char. Thx
3
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
8
by: Carlos | last post by:
I have a strinf with comma separated field. Is is possible to convert it to a Structure ? Thanks
6
by: MrKrich | last post by:
I want to convert Hexadecimal or normal integer to Binary. Does VB.Net has function to do that? I only found Hex function that convert normal integer to Hexadecimal.
5
by: Mika M | last post by:
Hi! I've made little code to convert string into hex string... Public ReadOnly Property ToHexString(ByVal text As String) As String Get Dim arrBytes As Integer() = CharsToBytes(text) Dim sb...
14
by: Drew | last post by:
Hi All: I know I am missing something easy but I can't find the problem! I have a program which reads an integer as input. The output of the program should be the sum of all the digits in the...
20
by: Niyazi | last post by:
Hi all, I have a integer number from 1 to 37000. And I want to create a report in excel that shows in 4 alphanumeric length. Example: I can write the cutomerID from 1 to 9999 as: 1 ---->...
3
by: priyanka | last post by:
Hi there, I want to convert a String into integer. I get the string from a file using : string argNum; getline(inputStream,argNum); I now need to convert argNum into integer.
7
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006...
7
by: shellon | last post by:
Hi all: I want to convert the float number to sortable integer, like the function float2rawInt() in java, but I don't know the internal expression of float, appreciate your help!
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.