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

# convert string to integer

 P: n/a 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 Replies

 P: n/a In article <11**********************@h48g2000cwc.googlegroups .com>, when i used atoi, values greater than 32767 are converted into negativevalues. 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

 P: n/a Walter Roberson said: In article <11**********************@h48g2000cwc.googlegroups .com>, I have a string array which may contain 5 digit values >>when i used atoi, values greater than 32767 are converted into negativevalues. 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

 P: n/a Hi, how to reverse a string recursively in place thank you Sep 18 '06 #4

 P: n/a Hi, how to reverse a string recursively in place thank you Sep 18 '06 #5

 P: n/a 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

 P: n/a In article , Richard Heathfield 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

 P: n/a 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 San Diego Supercomputer Center <* We must do something. This is something. Therefore, we must do this. Sep 18 '06 #8

 P: n/a 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

 P: n/a 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

 P: n/a Walter Roberson said: In article , Richard Heathfield >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

 P: n/a 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 discussion thread is closed

Replies have been disabled for this discussion.