Translate

星期一, 3月 19, 2007


#include

void int2hex(int nvalue,unsigned char *szhexstr);
int i,j,k;

void main( void )
{

int nvalue=0;
// unsigned char szhexstr[120];
unsigned char *szhexstr=0;
// szhexstr = malloc( 120 );

printf("pls key a integer:\n");
scanf("%d",&nvalue);

int2hex(nvalue,szhexstr);

printf("the string is %s\n",szhexstr);

// free( szhexstr );
}

void int2hex(int nvalue,unsigned char *szhexstr)
{


int temp,quotient=30;

unsigned char buffer=2;
if(nvalue>=16)
{

while(quotient<16)
{
quotient=nvalue/16;
temp=nvalue%16;
i=temp;

}
buffer=(quotient<<4)|i;
}

else
szhexstr=&buffer;
}



用VISTUAL C++ COMPILE 遇到兩個問題
一.要給定初值
二.在i j k的變數定義在函數內會有問題 雖然定義為外部變數可以解決問題 還是覺得很奇怪
夜深人靜和C語言廝殺中
持盈保泰