I'm having problem using pointers and arrays in C, the task is simple i have a function that converts digits into a int array then send back a pointer to this array. At this point i need to assign this pointer into an array of pointers.
What i get is a bunch of number in sequence, so i suppose those are adresses of pointers, problem is i need to see the value stored in those arrays not the adresses...
Program compile without warnings or error.
//-----Function to convert single digits-----
int* convertToBits(int digitToConvert)
{
int binaryDigit[8];
int k;
for (int i = 7; i >= 0; i--) {
k = digitToConvert >> i;
if (k & 1) {
binaryDigit[i] = 1;
//printf("1");
}
else {
binaryDigit[i] = 0;
//printf("0");
}
}
return binaryDigit;
}
//-----Function to store single digits-----
void setupDigit(int temperature)
{
int* displayDigit[4];
if (temperature >= 0)
{
for (int i = 0; i < 4; i++) {
//displayDigit[i] = convertToBits(takeSingledDigit(temperature));
int* pointTo = convertToBits(takeSingledDigit(temperature));
displayDigit[i] = pointTo;
for (int j = 0; j < 8; j++) {
printf("%d", *(displayDigit[i]) + j);
}
printf("\n");
temperature /= 10;
}
}
else
{
for (int i = 0; i < 3; i++) {
//displayDigit[i] = convertToBits(takeSingledDigit(temperature));
int* pointTo = convertToBits(takeSingledDigit(temperature));
displayDigit[i] = pointTo;
for (int j = 0; j < 8; j++) {
printf("%d", *(displayDigit[i]) + j);
}
printf("\n");
temperature /= 10;
}
displayDigit[3] = minusChar;
}