int to char

Hello,

i have a char array bla, where I need to put 0 and 1 as first to values of bla.
latter on, i need to compare these two values, but if I do it like I did on line 5 , 6 and 15, the value wont even be printed. I tried to do some convertions but I wasnt succesful.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
char *bla = NULL;
char *from = "hello";
bla = new char[len];
	int i;
	bla[0] = 0;
	bla[1] = 1;

	for(i = 2; i < len - (int)strlen(from)-1; i++)
	{
		do {
			bla[i] = (char)rand();
		} while(bla[i] == 0);
	}

        bla[i] = 0;
        i++;

	for(int j = 0;j<(int)strlen(from);j++)
	{
		bla[i] = from[j];
		i++;
	}
	bla[i]= '\0';
	std::cout << bla;

        if(bla[0] != 0) std::cout << "is not zero\n";
        else std::cout << "ok\n";


thanks for your help.
Last edited on
Use string instead. You can intialize a string from an integer and concatenate on just about anything. What are you trying to accomplish? What is the actual problem?
if I used string I had to change loats of things in my program, which is quite long now.
I am trying to put some padding to the string "hello", 2 first values have to be 0 and 1. after that can be any value and then "hello". latter I need to remove this padding. and the problem is, how to put 0 and 1 to that field, so I could later compare if this values are right and the string "hello" has the right padding.
Last edited on
Topic archived. No new replies allowed.