472,782 Members | 1,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Unable to convert integer to character

Hi,

I am having problem in converting an integer to character in the following program. It compiles but at run time there is no value in c.

Could anyone help me with the problem. It is very urgent.


int main()
{
int a = 3;
char c = (char)a;

printf("Conversion to char c = %c \n", c);
return 0;
}

What should i do to store integer 3 as character in c?
Jan 19 '08 #1
2 3928
Savage
1,764 Expert 1GB
Hi,

I am having problem in converting an integer to character in the following program. It compiles but at run time there is no value in c.

Could anyone help me with the problem. It is very urgent.


int main()
{
int a = 3;
char c = (char)a;

printf("Conversion to char c = %c \n", c);
return 0;
}

What should i do to store integer 3 as character in c?
Add to c ASCII value of 48.(which is 0),or just add '0';
Jan 19 '08 #2
weaknessforcats
9,208 Expert Mod 8TB
A char is an integer. However, you asked printf() to dispay the integer as a letter rather than a value with the %c format. Try %d.

Be sure to follow Savage's directions.
Jan 20 '08 #3

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

Similar topics

4
by: David Lawson | last post by:
I know how to conver a string to an array of strings, but I need to convert an ascii string to an array of integers (really unsigned chars). Eg, $str ="ABC"; needs to convert to something...
1
by: Ayokunle Giwa | last post by:
Why do I keep getting this error in the function to insert data below, any help would be apprecaited: CREATE OR REPLACE FUNCTION public.add_apppointment (date, time, integer,time, boolean, text,...
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
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 ---->...
1
mahet
by: mahet | last post by:
Anders Jansson was a guest here, and he was having problem: When I try to build the web, this error is displayed: ---> Error 5 Unable to convert input xml file content to a DataSet. Invalid...
5
by: Les Caudle | last post by:
I've got some C# 2.0 code that has been working for a year. using (XmlWriter w = XmlWriter.Create("out.xml" ,settings)) { // many lines of code to write to w...
10
by: cmdolcet69 | last post by:
Public ArrList As New ArrayList Public bitvalue As Byte() Public Sub addvalues() Dim index As Integer ArrList.Add(100) ArrList.Add(200) ArrList.Add(300) ArrList.Add(400) ArrList.Add(500)
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{

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.