473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Convert two char into one int

I have this lines:

char *chr;
int integ;
num[0] = '1';
num[1] = '9';

How I could obtain value 19 in the integ variable????
Hi to all.
Jun 27 '08 #1
5 6827
In article <8a**********************************@e39g2000hsf. googlegroups.com>,
Mariano <ma**************@gmail.comwrote:
>I have this lines:

char *chr;
int integ;
num[0] = '1';
num[1] = '9';

How I could obtain value 19 in the integ variable????
Hi to all.
Continue with:

num[2] = 0;
sscanf(num,"%d",&integ):

Jun 27 '08 #2
Mariano wrote:
I have this lines:

char *chr;
int integ;
num[0] = '1';
num[1] = '9';

How I could obtain value 19 in the integ variable????
Assuming `num' is an array of characters (two or more),

integ = (num[0] - '0') * 10 + (num[1] - '0');

will do it.

--
Er*********@sun.com
Jun 27 '08 #3

"Mariano" <ma**************@gmail.com>
:8a**********************************@e39g2000hsf. googlegroups.com...
>I have this lines:

char *chr;
int integ;
num[0] = '1';
num[1] = '9';

How I could obtain value 19 in the integ variable????
Hi to all.
integ = atoi(num[0])*10+atoi(num[1]);
Jun 27 '08 #4
Fred Yu wrote:
"Mariano" <ma**************@gmail.com>
:8a**********************************@e39g2000hsf. googlegroups.com...
>I have this lines:

char *chr;
int integ;
num[0] = '1';
num[1] = '9';

How I could obtain value 19 in the integ variable????
Hi to all.

integ = atoi(num[0])*10+atoi(num[1]);
That's wrong.
num[0] is not a pointer to a string.
atoi takes a pointer to a string as an argument.

int atoi(const char *nptr);

--
pete
Jun 27 '08 #5
On 26 Jun, 02:15, pete <pfil...@mindspring.comwrote:
Fred Yu wrote:
"Mariano" <mariano.calan...@gmail.com>
:8a82a41a-1992-4fa3-9c9b-bc4f6c2b3...@e39g2000hsf.googlegroups.com...
I have this lines:
char *chr;
int integ;
num[0] = '1';
num[1] = '9';
How I could obtain value 19 in the integ variable????
Hi to all.
integ = atoi(num[0])*10+atoi(num[1]);

That's wrong.
num[0] is not a pointer to a string.
and num may not be a valid string, we don't
know if there's a terminating nul character
atoi takes a pointer to a string as an argument.
and has poor error handling
int atoi(const char *nptr);

--
Nick Keighley
Jun 27 '08 #6

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

Similar topics

5
by: Brad Moore | last post by:
Hey all, I'm getting the following compiler error from my code. I was wondering if anyone could help me understand the concept behind it (I actually did try and compile this degenerate...
7
by: MilanB | last post by:
Hello How to convert char to int? Thanks
2
by: Alper Akcayoz | last post by:
Hello Esteemed Developpers I would like to thank you in advance for your sincere responses I am a fresh Visual C++ .NET Developer. Can you kindly guide me for How to Convert char* to System::String
1
by: Elioth | last post by:
Hi... I need to know how to convert Char Array to Byte Array and vice-versa in VB 2K5 Thanks for all help. Elioth
2
by: Joah Senegal | last post by:
Hello I need to convert a chat to a string... but I don't know how to do this. i;ve searched the internet but I've only find some code to convert char * to string or char to string.... but I...
3
by: simon | last post by:
I am a fresh Visual C++ .NET Developer. Can you kindly guide me for How to Convert char to System::String I am using windows forms and trying to set a text value referencing the method...
2
by: Rasheed | last post by:
Hi, i have a char pointer buffer which will hold the bitmap buffer, So i need to convert char *buffer as a bitmap. becuase when i draw on the Dialog using char *buffer. Nothing will be dispalyed....
1
by: helios | last post by:
Hi all, I'm resolved problem. and I want anybody need me that convert char to array bits char ConvertChar2ArrayBit(char ch) { char Bits; .... return Bits; } for...
3
by: mamul | last post by:
Hi please some one can help me. how to convert char * to string? i have take char *argv from command line and want to pass to a function as string object(string str) i want to first convert argv...
3
by: DaveRook | last post by:
Hi I've had a few error messages with this I don't understand why. It works fine in a Windows Form, but now moving it to a website, it's not working. I don't have the option to count the lines as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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,...

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.