Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Write two functions to convert BCD codes to corresponding digital strings.
Write two functions to convert BCD codes to corresponding digital strings.

//////////////////////////////////////////// p>

// C-Free 4.1

// MinGW 3.4.5

// veket’s trumpet

// passed

p>

//

//Write bcd2str for you

//Leave it to yourself to figure it out

//Enter 0x780x890x500xff

< p>//No spaces

//Output 879805

/////////////////////////// ////////////////

#include

#include

void bcd2str(char *m, char *n);

void str2bcd(char *m, char *n);

int main()

{

char bcd[1024];

char str[1024];

printf("input bcd:\n");

gets(bcd);

bcd2str(bcd, str);

printf("str = %s\n", str);

// printf("input str:\n");

//gets(str)

//str2bcd(s);

//printf(" bcd = %s\n", bcd);

return 0;

}

void bcd2str(char *m, char *n)

{

int len;

char *p1;

char *p2;

p1 = m;

p>

p2 = n;

while(*p1)

{

p1++;

}

len = p1 - m;

if(len%4)

{

strcpy(p2, "error!\n");< /p>

return;

}

if(strcmp(p1-4,"0xff"))

{

strcpy(p2, "error!not end with \"oxff\"\n");

return;

}

for(p1=m +3,p2=n;p1

{

*p2 = *p1;

*(p2+1) = *(p1-1);

}

*p2 = '\0';

}

//void str2bcd(char *m, char *n)

//{

//

//}< /p>