This will only work for int-digits 0-9, but your question seems to suggest that might be enough.
It works by adding the ASCII value of char '0' to the integer digit.
int i=6;
char c = '0'+i; // now c is '6'
For example:
'0'+0 = '0'
'0'+1 = '1'
'0'+2 = '2'
'0'+3 = '3'
Edit
It is unclear what you mean, "work for alphabets"?
If you want the 5th letter of the alphabet:
int i=5;
char c = 'A'-1 + i; // c is now 'E', the 5th letter.
Note that because in C/Ascii, A is considered the 0th letter of the alphabet, I do a minus-1 to compensate for the normally understood meaning of 5th letter.
Adjust as appropriate for your specific situation. (and test-test-test! any code you write)
"I have int i = 6; and I want char c = '6' by conversion. Any simple way to suggest?"
There are only 10 numbers. So write a function that takes an int from 0-9 and returns the ascii code. Just look it up in an ascii table and write a function with ifs or a select case.
Doing college work I gathered the data I found and gave me this result:
"The input consists of a single line with multiple integers, separated by a blank space. The end of the entry is identified by the number -1, which should not be processed."
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
char numeros[100]; //vetor para armazenar a entrada dos numeros a serem convertidos
int count = 0, soma = 0;
cin.getline(numeros, 100);
system("cls"); // limpa a tela
for(int i = 0; i < 100; i++)
{
if (numeros[i] == '-') // condicao de existencia do for
i = 100;
else
{
if(numeros[i] == ' ') // condicao que ao encontrar um espaco manda o resultado dos dados lidos e zera a contagem
{
if(count == 2) // se contegem for 2 divide por 10 por nao ter casa da centena
soma = soma / 10;
if(count == 1) // se contagem for 1 divide por 100 por nao ter casa da dezena
soma = soma / 100;
cout << (char)soma; // saida das letras do codigo ascii
count = 0;
}
else
{
count ++; // contagem aumenta para saber se o numero esta na centena/dezena ou unitaria
if(count == 1)
soma = ('0' - numeros[i]) * -100; // a ideia é que o resultado de '0' - 'x' = -x (um numero inteiro)
if(count == 2)
soma = soma + ('0' - numeros[i]) * -10; // todos multiplicam por -1 para retornar um valor positivo
if(count == 3)
soma = soma + ('0' - numeros[i]) * -1; /* caso pense em entrada de valores na casa do milhar, deve-se alterar esses 3 if´s
alem de adicionar mais um para a casa do milhar. */
}
}
}
return 0;
}