C String Conversion Problem, C How to Convert Integer to Character Type?

Updated on technology 2024-02-09
6 answers
  1. Anonymous users2024-02-05

    Use the ITOA function.

    Prototype: extern char *itoa(int i);

    #include<

    #include<

    int main()

    int a=125;

    char b[50];

    printf("%s",itoa(a,b,10));Convert 125 in decimal 10 to characters and output it.

    return 0;

  2. Anonymous users2024-02-04

    First of all, the char character should be output with %c, %d is the output of integer numbers, but since the characters and integers are compatible, the char character can also be output with %d, although the output result is not the desired result ......

    Since all symbols are stored in ASCII code corresponding to 0 255, it is necessary to convert c=130 to binary, which is the state of c=130 in memory.

    130 to binary string is"1000

    0010"However, the data in the computer is stored in complements, so this"10000010"It's a complement, then the complement is 1000

    What is the number of 0010?

    So the key to outputting -126 is to use %d.

    d", when out, because "1000."

    0010" is 8-bit, which should obviously be short

    int, so the compiler automatically interprets it as"hd", (note that the highest bit is 1) so it is interpreted as -126

  3. Anonymous users2024-02-03

    Not of the same type, character'a'It only takes up one byte, and the string is followed by a closing character'\0', therefore"a"The actual storage space station is two bytes, for.

  4. Anonymous users2024-02-02

    It's different.

    characters'a'In C Ann ASCII storage.

    Strings"a"The A in it is replaced by a string, eg "efw34" or something, which is a string.

    If you put the string t="efw34"; This defines the output function to write printf("%s",t);It's equivalent to printf( "efw34");

  5. Anonymous users2024-02-01

    Not of the same type, in memory 'a' occupies one byte and 'a' occupies two bytes ('a''\0')

  6. Anonymous users2024-01-31

    It is different that a single quotation mark encloses a character, and a double quotation mark encloses a string, and the string will be followed by a '0' as the ending flag of the string, and '0' is also a character.

Related questions
4 answers2024-02-09

Just take a look at this one**.

Hope it helps. >>>More

7 answers2024-02-09

Do it by your train of thought.

Method 1. string strnumber="200m"; >>>More

9 answers2024-02-09

Scope. You static char *chh;

static char *ch1;Although the address pointed to by the two pointers does not change, have you ever wondered whether the memory address they point to has been released, char chc[10]; It's local, the function is out, the lifecycle is over, and you're trying to access it with a pointer in void times(). >>>More

11 answers2024-02-09

First of all, it is necessary to understand what a binary tree is (and I guess the subject also understands). >>>More

24 answers2024-02-09

Operate from right to left, -i--so calculate -i first--, the operation level is higher, so it can be written as -(i--)i--for 8, add a - sign, so -i--is 8, at this time i--after, i=7, and then -i++ is the same, can be written as -(i++) so -i++ is -7, at this time i++ becomes 8,--i, subtract 1 before execution, so --i is 7, at this time i=7, ++i is the same, add 1 before executing i, so ++i is 8, at this time i=8, then calculate i--,i--is still equal to 8, then i minus one becomes 7, i++, i++ is equal to 7, and then i++, i=8, so finally i=8, and then print it out in turn, pay attention to the operation is from right to left, but print from left to right print i,i++,i--,i,--i,-i++,i-, so the check mark result is out.