Character array output/output

(1) Scanf and printf
can use the output of %c loop until the judgment condition is'\0' or null end; %s can also be used, but you need to pay attention to the fact that %s encounters spaces and newlines to identify a string the end.
(2) getchar and putchar
input and output and output a single character.
(3) Gets and puts
gets are used to input a line of character strings (recognizing the newline character \n as the end of the input, so after scanning an integer, if you want to use gets (gets_s), you need to use getchar to receive the newline character after the integer); puts Used to output a line of string, that is, output a one-dimensional array on the interface, followed by a newline.

Note:
(1) After the character array is defined, a'\0' is automatically appended as the end mark;
(2) The ASCII code of the end character'\0' is 0, that is, NULL occupies one character bit, so The capacity of the character array is 1 more than the actual length of the string to be stored;
(3) If you do not use the %s or gets function of the scanf function to input the character array (for example, use getchar), please be sure to add it after each character array you input '\0', otherwise the output will be garbled.

Guess you like

Origin blog.csdn.net/KO812605128/article/details/115190905