Ma perchè non mi funziona la oct2dec???
Scommetto che è un problema di puntatori. Dove posso trovare una guida che mi spieghi esattamente come funzionano i puntatori in modo da non avere dubbi? Grazie
#include <stdio.h>
#include <stdlib.h>
void dec2bin(unsigned int data, short int bitSeq[32]);
void bin2dec(unsigned int *data, short int bitSeq[32]);
void dec2oct(unsigned int data, short int octSeq[11]);
void oct2dec(unsigned int *data, short int octSeq[11]);
short int bitSeq[32];
short int octSeq[11];
short int a[]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1};
short int b[]= {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
short int c[]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1};
short int d[]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1};
short int e[]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
short int f[]= {0,0,0,0,0,0,0,0,7,2,5};
short int g[]= {0,0,0,0,0,0,0,0,0,2,5};
short int h[]= {0,0,0,0,0,0,0,0,1,2,5};
short int i[]= {0,0,0,0,0,0,0,0,0,3,3};
short int l[]= {0,0,0,0,0,0,0,0,0,1,2};
int main(){
/*printf("\n DEC2BIN\n");
dec2bin(7,bitSeq);
dec2bin(32,bitSeq);
dec2bin(70,bitSeq);
dec2bin(153,bitSeq);
dec2bin(52150,bitSeq);
printf("\n\n\n DEC2OCT\n");
dec2oct(8,octSeq);
dec2oct(35,octSeq);
dec2oct(124,octSeq);
dec2oct(888,octSeq);
dec2oct(9625,octSeq);
printf("\n\n\n BIN2DEC\n");*/
unsigned int data = 0;
/*bin2dec(&data,a);
printf("\n IN DECIMALE :%d",data);
data=0;
bin2dec(&data, b);
printf("\n IN DECIMALE :%d", data);
data=0;
bin2dec(&data, c);
printf("\n IN DECIMALE :%d", data);
data=0;
bin2dec(&data, d);
printf("\n IN DECIMALE :%d", data);
data=0;
bin2dec(&data, e);
printf("\n IN DECIMALE :%d", data);
data=0;*/
printf("\n\n\n OCT2DEC\n");
oct2dec(&data, f);
printf("\n IN DECIMALE :%d",data);
data=0;
/* oct2dec(&data, g);
printf("\n IN DECIMALE :%d", data);
data=0;
oct2dec(&data, h);
printf("\n IN DECIMALE :%d", data);
data=0;
oct2dec(&data, i);
printf("\n IN DECIMALE :%d", data);
data=0;
oct2dec(&data, l);
printf("\n IN DECIMALE :%d", data);
data=0;*/
getchar();
system("npause");
return 0;
}
void oct2dec(unsigned int *data, short int octSeq[11]){
int j;
unsigned int n;
printf("\n IL NUMERO OTTALE: ");
for(j=0;j<11;j++) {
printf("%d",octSeq[j]);}
for(j = 0; j < 11; j++){
n=octSeq[j];
(*data) = (*data)+ n << (3*octSeq[j]);
}
/*int n,r,i;
n=oct;
oct=0;
for(i=0;n!=0;i++)
{
r=n%10;
oct=oct+r*poww(8,i);
n=n/10;
}
return oct;*/
}
void bin2dec(unsigned int *data, short int bitSeq[32]){
int j=0;
printf("\n IL NUMERO BINARIO: ");
for(j=0;j<32;j++) {
printf("%d",bitSeq[j]);}
for(j = 0; j < 32; j++){
(*data) |= bitSeq[j] << (32 - (j+1));}
}
void dec2oct(unsigned int data, short int octSeq[11]){
int i=0;
int r=0;
int j=0;
printf("\n IL NUMERO %u",data );
printf(" IN OTTALE : ");
for(i=0;i<11;i++){
r=data%8;
if (r==0)
octSeq[i]=0;
if (r==1)
octSeq[i]=1;
if (r==2)
octSeq[i]=2;
if (r==3)
octSeq[i]=3;
if (r==4)
octSeq[i]=4;
if (r==5)
octSeq[i]=5;
if (r==6)
octSeq[i]=6;
if (r==7)
octSeq[i]=7;
data=data/8;
}
for(j=10;j>-1;j--)
printf("%d",octSeq[j]);
}
void dec2bin(unsigned int data, short int bitSeq[32]){
int i=0;
int r=0;
int j=0;
printf("\n IL NUMERO %u",data );
printf(" IN BINARIO : ");
for(i=0;i<32;i++){
r=data%2;
if (r==0)
bitSeq[i]=0;
else
bitSeq[i]=1;
data=data/2;
}
for(j=31;j>-1;j--)
printf("%d",bitSeq[j]);
}