The C language assigns a string to an array of type char.

Source: Internet
Author: User

Char CharType                      [6]; //Defines an array of type char.

strcpy          (CharType, "0.001"); //assigns the string "0.001" to the CharType array.

itoa       (i_value_flag, CharType); //converts the int variable to a string, and assigns the value to the Chartype array.

when I converted the int variable to a string, I found the string displayed in reverse order. Like I_value_flag equals 123456, on the interface.

The display is 654321,(Of course strcpy (CharType, "123456") can be displayed 123456).

All I wrote again was the function of a reverse order.

j = 0;
i = 0;

   while (j==0) {
if (Chartype[i]==0) {
j = 1;
}Else {
i++;
}
if (i>5) J=1;
}//Here first count the valid characters is how many, if the valid character is 4, the storage effect is ' 4 ' 3 ' 2 ' 1 ' + ', because ' the ' + ' does not reverse the order, so the statistics to the 4 valid number is stored in the I variable inside.

i--;
j=0;

   while(j==0) {
if(Chartype[i]= = ' 0 ' && i>0) {
Chartype[i]= ' + ';
i--;
}ElseJ=1;
}//Clear out the extra 0, if it is next to the ' + ' character, ' 0 ' exists, change this ' 0 ' to ' + '. Because I mostly show numbers

K = I/2;//If I equals odd, for example I equals 5, just K equals 2. That is, the third person does not swap.
L = i;
   for(i=0;i<k;i++) {
C_value_flag =Chartype[l-i];
Chartype[l-i]=Chartype[i];
Chartype[i]=C_value_flag;
}//adjust to the order of valid characters, such as 1 and 5 swap, 2 and 4 swap, 3 unchanged.

The C language assigns a string to an array of type char.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.