473,405 Members | 2,334 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,405 software developers and data experts.

Convert char to integer

114 100+
Is it possible to convert a char to an int or reverse.
eg. int x = 12345
is it pssible to make char y[10] = "12345" without user input?
Jul 17 '07 #1
3 5366
Meetee
931 Expert Mod 512MB
Is it possible to convert a char to an int or reverse.
eg. int x = 12345
is it pssible to make char y[10] = "12345" without user input?
You can do like this:
Expand|Select|Wrap|Line Numbers
  1. int i = 12345;
  2. char c = static_cast<char>(i);
  3.  
OR
Expand|Select|Wrap|Line Numbers
  1. int a = 12345;
  2. char * b= new char [50];                        
  3. itoa(a, b, 10); //b will now contain the value you want as a string
  4.  
Regards
Jul 17 '07 #2
ilikepython
844 Expert 512MB
You can do like this:
Expand|Select|Wrap|Line Numbers
  1. int i = 12345;
  2. char c = static_cast<char>(i);
  3.  
OR
Expand|Select|Wrap|Line Numbers
  1. int a = 12345;
  2. char * b= new char [50];                        
  3. itoa(a, b, 10); //b will now contain the value you want as a string
  4.  
Regards
The C++ way is using a stringstream object:
Expand|Select|Wrap|Line Numbers
  1. #include <sstream>
  2. int a = 12345;
  3. string astr;
  4. stringstream ss;
  5. ss << a;
  6. ss >> str; // str now contains 12345 as a string
  7.  
Jul 17 '07 #3
Firecore
114 100+
Thanx for that.
I think i will stick to the c method.
I do not know how to use C++
Jul 17 '07 #4

Sign in to post your reply or Sign up for a free account.

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
4
by: Kay | last post by:
how to convert int to char * ? I have found this in a web site. However, it doesn't work even I change itoa to atoi including stdlib.h char str; int i=567; str=itoa(i, str, 10);
7
by: MilanB | last post by:
Hello How to convert char to int? Thanks
1
by: YXQ | last post by:
Hello, i want to convert to VB.NET, i have try the url(http://authors.aspalliance.com/aldotnet/examples/translate.aspx), but the converted codes will not work. Thank you! The C# code...
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.
4
by: msosno01 | last post by:
I have Java client that connects to C++ server. The client sends integer in binary using DataOutputStream write function. I am reading these data into buffer. I have to convert this buffer back...
11
by: lenygold via DBMonster.com | last post by:
I am tryieng to convert our time consuming recursive queries too very efficient queries based on nested set model. The only problem is to convert an adjacency list model into a nested set model,...
14
by: rtillmore | last post by:
Hello, I did a quick google search and nothing that was returned is quite what I am looking for. I have a 200 character hexadecimal string that I need to convert into a 100 character string. ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.