I'm trying to get work this program but I'm failing. I don't know where I'm wrong. I get segmentation fault. It's probably the error is due to a pointer that doesn't work.
#include <stdio.h>
#include <stdlib.h>
void ConvertBin(int n, int *ris,int *bit);
int main(int argc, char *argv[])
{
int n;
int ris[20];
int bit;
printf("Insert num: "); scanf("%d", &n);
ConvertBin(n,ris,&bit);
for (int i=bit; i!=0; i--)
{
printf("%d", *(ris+i));
}
return 0;
}
void ConvertBin(int n, int *ris, int *bit)
{
int i = 0;
while (n!=0)
{
*(ris+i) = n%2;
n = n/2;
i++;
}
bit = &i;
}