473,383 Members | 1,733 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,383 software developers and data experts.

Displaying an Int as a string?

Is there anyway to convert a variable of data type int to a word or constant character in c?

I'm working on a problem where there was a data type created and the words paper, rock, and scissors are now 0, 1, and 2. I need to printf what was chosen and because the player/machine choices are now represented as integers I don't know how to actually print paper, rock or scissors.
Nov 13 '07 #1
3 1105
sicarie
4,677 Expert Mod 4TB
Is there anyway to convert a variable of data type int to a word or constant character in c?

I'm working on a problem where there was a data type created and the words paper, rock, and scissors are now 0, 1, and 2. I need to printf what was chosen and because the player/machine choices are now represented as integers I don't know how to actually print paper, rock or scissors.
Well, you can do that one of several ways. You can have an if else chain
Expand|Select|Wrap|Line Numbers
  1. if (i_choice == 1)
  2. //.....
  3. else if (i_choice == 2)
  4. //.... do whatever
  5. else....
  6.  
Or you can have a case
Expand|Select|Wrap|Line Numbers
  1. switch(i_choice)
  2. case 1:
  3. //... whatever 1 is (say rock)
  4. break;
  5. case 2:
  6. //...wahtever 2 is
  7. break;
  8. //.... and so on.
  9.  
However, your original question was converting an into to a string/char which is done with the itoa() function.
Nov 13 '07 #2
Well, you can do that one of several ways. You can have an if else chain
Expand|Select|Wrap|Line Numbers
  1. if (i_choice == 1)
  2. //.....
  3. else if (i_choice == 2)
  4. //.... do whatever
  5. else....
  6.  
Or you can have a case
Expand|Select|Wrap|Line Numbers
  1. switch(i_choice)
  2. case 1:
  3. //... whatever 1 is (say rock)
  4. break;
  5. case 2:
  6. //...wahtever 2 is
  7. break;
  8. //.... and so on.
  9.  
However, your original question was converting an into to a string/char which is done with the itoa() function.

Thanks. I used the if else and it worked.
Nov 13 '07 #3
sicarie
4,677 Expert Mod 4TB
Thanks. I used the if else and it worked.
Glad I could help. Feel free to post again if you get stuck.
Nov 13 '07 #4

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

Similar topics

1
by: Dave Posh | last post by:
I seem to be having a problem displaying time stored in mysql. The format stored in the database is 13:15:05. The database data type is time. I'm using asp vbscript and sql to retrieve the time...
0
by: Fronky | last post by:
Hope someone can help. I am still learning, so no laughing please. I am displaying records from a database using Response.Write(""); instead of the usual datagrid method. I am doing it this way...
1
by: asad | last post by:
hello how ru all, i have some problem in displaying xml file in asp.net, i successfully create an xml file but when want to display it through ASP.NET code it throwing following error. ...
0
by: Phil G. | last post by:
Hi, my 'project' requires that I create a form with text info. at set time periods. These time periods are not evenly spaced so I pass a param for the delay(seconds). In order to debug this I have...
5
by: Bill | last post by:
Hello, Could anyone post some simple code or advise me on how I can display the SSN number like *****7890 in a text box, even thought the user entered 1234567890, and the value of the variable...
11
by: prats | last post by:
I want to write a GUI application in PYTHON using QT. This application is supposed to take in Japanese characters. I am using PyQt as the wrapper for using QT from python. I am able to take input...
2
by: mazdotnet | last post by:
Hi, I have the following code in the code-behind file public string section; section = Request.ToString() and I like to display it in my .aspx page (included .ascx) but it's not working.
7
by: Jonathan Wood | last post by:
Okay, I have a site that displays information based on user input, a couple of the items are plain strings that the user entered. I understand the risk here is that they could insert javascript...
2
by: Garima12 | last post by:
I am writing following code to fetch the data from database, using stored procedure. problem is it is highlighting ByVal and when I mouse over, it is displaying expression expected. Please anyone...
10
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i have text like this: "ACPI\GENUINEINTEL_-_X86_FAMILY_6_MODEL_13\_0" an after displaying it in a RichTextBox as RTF string, i get this: "ACPI_-_x86_Family_6_Model_13 "
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.