问题要求:输入一段12位的16进制字符串,确认输入合法后转换为2进制字符串,按010101010这样的格式输出这段12×4位的2进制字符串文件
在DEV C++ 4.9.9.2下能编译通过
[此贴子已经被作者于2007-7-20 16:30:40编辑过]
----------------解决方案--------------------------------------------------------
#include<conio.h>
#include<stdlib.h>
char *pmac,*pmac_2;
void check (char *);
main()
{
putmac(pmac);
printf("%s\n",mac);
getche();
return 0;
}
char *putmac (char *p)
{
&mac[0]=*p;
printf ("\nEnter the MAC : ");
scanf ("%s",&mac);
check (mac);
printf ("\nThe MAC your type is %s\n",mac);
return p;
}
//////////////////////////////////////////////////////////
void check (char *p)
{
p=&mac[0];
int i;
if (strlen(*pmac)!=12)
{
printf("\nTYPE ERRNO!\n");
putmac();
}
else
for (i=0;i<12;i++)
{
if (mac[i]>='0'&&mac[i]<='9'||mac[i]>='A'&&mac[i]<='F'||mac[i]>='a'&&mac[i]<='f')
continue;
else
{
printf("\nTYPE ERRNO!\n");
putmac();
}
}
return ;
}
----------------解决方案--------------------------------------------------------
//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\");
}
----------------解决方案--------------------------------------------------------
谢谢,可是我要的是C语言的代码
----------------解决方案--------------------------------------------------------
哦,看到了,再次谢谢
----------------解决方案--------------------------------------------------------
3楼很强,在此帮忙顶一个!!!!!
----------------解决方案--------------------------------------------------------
急急急。。。
[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编辑过]
----------------解决方案--------------------------------------------------------
运行结果
----------------解决方案--------------------------------------------------------
为什么还没人~~~啊,急死了
----------------解决方案--------------------------------------------------------