I'm sorry if this is confusing....So far I'm converting a decimal number into binary. While doing this, i store the digits for the binary representation into an int array.
EX: for the number 4. (this is done in dec2bin below)
temp[0] = 1
temp[1] = 0
temp[2] = 0
i would like to store this array into another array (say BinaryArray) that will contain multiple 'temp' arrays.
I would like the BinaryArray to declared main, passed to dec2bin, and the save a copy of the current temp array. then go to the next number.
I'm having trouble with figuring out the pointers and what not needed for this. If someone could help me with how to declare the needed array in main and how add to it from dec2bin.
Thanks! Main:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
void dec2bin(int term, int size);
int size, mincount;
int * ptr;
int x;
x=0;
scanf("%d %d", &size, &mincount);
printf("Variables: %d\n", size);
printf("Count of minterms: %d\n", mincount);
int input[mincount+1];
while(x < mincount){
scanf("%d", &input[x]);
x++;
}
x = 0;
while(x < mincount){
dec2bin(input[x], size);
Dec2bin :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 32
void
dec2bin(int term,int size){
int i, j, temp[size], remain, quotient;
quotient = term;
i = size-1;
// set all temp to 0
for(j=size-1;j>=0; j--){
temp[j] = 0;
}
//change to binary
while(quotient != 0){
remain = quotient % 2;
quotient/=2;
if(remain != 0){
temp[i] = 1;
} else {
temp[i] = 0;
}
i--;
}
//print array
for(i=0; i<size; i++)
printf("%d", temp[i]);
printf("\n");
}