Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to export char array to int array?
How to export char array to int array?
# Contains? & ltstdio.h & gt

# Contains? & ltstring.h & gt

typedef? Not signed? Charles? uchar

typedef? Not signed? intuint

//conversion function

//Temp? Character array

//pout? Int array

//Length? Character array length

//Assume that the character array contains an even number of elements.

//If it is odd, the following processing needs to be added:

//Check whether the length is odd, and if it is, dynamically allocate an array of length+1 char.

//Clear all data and copy the contents of Temp to the dynamically allocated array.

//According to the following case that the length is even.

//Release dynamically allocated memory

//According to the requirements of the problem, the int type should be stored in a small terminal.

//If you are smart, you can write a function to check the byte order.

Invalid? Exchange (const? Ucal? * Temperature? uint? * pout,? Ucal? Length)

{

int? Me? =? 0;

For what? (; ? Me? & lt? Length? /? 2; ? i++)

{

//small end, copy it directly in the original order.

//If it is a big end, you can change the byte order.

Memcpy (pout, temperature? 2);

pout++; //int pointer moves back one bit.

temp+= 2; //The character byte is shifted back two places.

}

}

//Test code

int? Major (invalid)

{

int? Me;

uint? Array [20]? =? {0};

Ucal? Start []? =? {0x80,0xF 1,0x58,0x03,0xC 1,0xEA,0x8F,0x 06 };

Exchange (start,? Array? sizeof(Start));

For what? (me? =? 0; ? Me? & lt? 20; ? i++)

{

What if? (array[i]? ! =? 0)

{

printf("0x%04X?" ,? array[I]);

}

}

printf(" \ n ");

Return? 0;

} output screenshot: