I am a new member , my question is about store one char array with 2 for loop to one char 2D array . I write the code and when call this function, it did not give any error but I could not see the result . this is my code :
class RArrays
{
public:
static char** RCharArray(int Size1, int Size2)
{
char** Array = new char*[Size1];
for (char Array1 = 0; Array1 < Size1; Array1++)
{
Array[Array1] = new char[Size2];
}
return Array;
}
};
The class RArrays is redundant, there's nothing in it.
The problem with RCharArray is that it moves the pointer of the char* array. You need to remember that address as that is the base address of your 2D array. So the code should look somthing like:
1 2 3 4 5 6 7 8 9
char** RCharArray(int Size1, int Size2)
{
char** Array = newchar*[Size1];
for (int i = 0; i < Size1; ++i)
{
Array[i] = newchar[Size2];
}
return Array;
}
Please use the code format tag to format your code.
But with this class , program did not get my char 2D array . Although I solved my problem by changing some part , now in the part of program that I change number to binary and store it in buffer when I display it some of numbers like 0 that should be 000 or 1 taht should be 001 had been shown just 0 or 1 and I need all three digit ?!
I wrote one program . for example in this program , I give number 8 to program and then it changes numbers 0 - 7 to binary and show the new numbers in 3 digit , like 4 is 100 . But there is a problem here that 0 , 1, 2 , 3 were shown 0 , 1 , 10 , 11 instead of 000 , 001 , 010 , 011 . I should said that I store every result in one char array[33] .
Now I want to know what can I do that get correct result ?
So to restate the problem, you're doing decimal to binary number conversion. The converted number is held in a char array. You want to see leading zeros and the code that prints the number is: