问题要求:输入一段12位的16进制字符串,确认输入合法后转换为2进制字符串,按010101010这样的格式输出这段12×4位的2进制字符串文件
在DEV C++ 4.9.9.2下能编译通过
[此贴子已经被作者于2007-7-20 16:30:40编辑过]
急急急。。。
[CODE]
#include <stdio.h>
int main()
{
int i;
char mac[12][4]={0};
char *Ptr = NULL;
printf("\n Enter the MAC : ");
Ptr = (char *)malloc(12 * 4 * sizeof(char));
if (NULL == Ptr)
{
exit (1);
}
for(i=0;i<12;i++)
{
;
;
switch (getche())
{
case '0': strcpy(&mac[i][4],"0000"); break;
case '1': strcpy(&mac[i][4],"0001"); break;
case '2': strcpy(&mac[i][4],"0010"); break;
case '3': strcpy(&mac[i][4],"0011"); break;
case '4': strcpy(&mac[i][4],"0100"); break;
case '5': strcpy(&mac[i][4],"0101"); break;
case '6': strcpy(&mac[i][4],"0110"); break;
case '7': strcpy(&mac[i][4],"0111"); break;
case '8': strcpy(&mac[i][4],"1000"); break;
case '9': strcpy(&mac[i][4],"1001"); break;
case 'A': strcpy(&mac[i][4],"1010"); break;
case 'B': strcpy(&mac[i][4],"1011"); break;
case 'C': strcpy(&mac[i][4],"1100"); break;
case 'D': strcpy(&mac[i][4],"1101"); break;
case 'E': strcpy(&mac[i][4],"1110"); break;
case 'F': strcpy(&mac[i][4],"1111"); break;
default: printf("\nTYPE ERRNO!\n"); exit (0);
}
}
printf("\n%s\n",mac[12][4]);
free(Ptr);
Ptr = NULL;
}
[/CODE]
这是我修改后的,问题是为什么老是输出的null值这是怎么回事?
[此贴子已经被作者于2007-7-20 15:35:05编辑过]