问题要求:输入一段12位的16进制字符串,确认输入合法后转换为2进制字符串,按010101010这样的格式输出这段12×4位的2进制字符串文件
在DEV C++ 4.9.9.2下能编译通过
[此贴子已经被作者于2007-7-20 16:30:40编辑过]
//language C++
#include <iostream>
#include <bitset>
using namespace std;#define INT64 long long
int main()
{
INT64 a;
cin>>hex>>a;
cout<<bitset<48>(a)<<endl;
}
/* language C */
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,i;
char buf[32+1];
for(i=1;i<=12;i++){
scanf(\"%1x\",&a);
printf(\"%4d\",atoi(itoa(a,buf,2)));
}
printf(\"\n\");
}
/*without calling library function*/
#include <stdio.h>char* map[16]={\"0000\",\"0001\",\"0010\",\"0011\",\"0100\",\"0101\",\"0110\",\"0111\",
\"1000\",\"1001\",\"1010\",\"1011\",\"1100\",\"1101\",\"1110\",\"1111\"};int main()
{
int a,i;
for(i=1;i<=12;i++){
scanf(\"%1x\",&a);
printf(\"%s\",map[a]);
}
printf(\"\n\");
}
急急急。。。
[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编辑过]