I am making a program which includes comaring 2 numbers (int's) but later I want to call another windows function and it takes in CHAR not int. I need a way to convert my ints to char. I looked up this on internet and non if it worked. Do you know any functions to do that without too much owkr and confusion. Also a number has long variables and it would be best if each integer was converted to char, for example

int i = 4234;
char[4] = convert(i);
for(int z = 0; z < 4; z++) {
cout << char[z} << "\n"
}

So I want the output to be
4
2
3
4
I need the convert function.

Recommended Answers

All 6 Replies

confused

you want to have a variable integer with number 4234
and take each digit separately?
if yes why you dont use modulus and division?

Why not use std::string? You can compare numbers and access the individual characters.

But I am using a function where you need const* char And thanks, I will check out String stream

an easy but messy way is :
- use divide and modulus to get the individual four numbers.
- convertion: use char value1 = int num1 + 48 (the number 48 is the ascii for zero character.)

std::string.c_str() returns a const char*

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.