该程序的目的是采用十六进制数字(例如“ 10”或“ 01”)进行转换
二进制等于00010000和000000001。
这是一个非常复杂的程序的伪代码尝试:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <stdbool.h>
int main(int argc, char ** argv) {
int * a1;
int * a2;
array[0] = 10;
array[1] = 01;
a1 = HexToBin(array[0]);
a2 = HexToBin(array[1]);
printf("here is binary of the hex number '10' %d", a1); //THIS SHOULD PRINT 00010000
printf("here is binary of the hex number '01' %d", a2); //THIS SHOULD PRINT 00000001
}
int * HexToBin(char * array) {
int i;
for (i = 0; i < 2; i++) {
switch (array[i]) {
case '0':
return 0000;
break;
case '1':
return 0001;
break;
default:
break;
}
}
}
我怎样才能做到这一点?
最佳答案
您的printf
语句打印的是a1
和a2
的地址,而不是该地址的内容。您需要使用*
取消引用或使用下标符号a1[0]
。
另外,您的HexToBin方法应返回'int而不是int *。
关于c - 我的数组函数未返回变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58894988/