Characters and strings (novice, c language)

1. Strings: 
What you need to know about strings:

1. The C language stipulates that the end of the string constant is marked with '\0', so that the system can judge whether the string ends.
2. The length of the string refers to the number of characters in the string (the characters here refer to Western characters, one Chinese character is equivalent to two Western characters, excluding the terminator), so the actual occupied by the
  string The number of bytes in the memory space is 1 more than the length of the string, that is: one more memory location of '\0'.
3. When writing a character string, the user does not need to write it, it will be automatically added by the C compilation system, and it will not be displayed on the screen.
4. Ordinary character sequences and character strings can be stored in the character array, which are distinguished by whether there is a string terminator '\0' at the end of the character array. If there is '\0' at the end of the character array,
  it stores a string, otherwise it stores a sequence of ordinary characters

//gets() input string 
//put() output string 

#include<stdio.h>
#include<string.h>
int main()
{     char str[20]; /* The first input method can input and output normally, and spaces can be input and output.     scanf("%s" ,str);     printf("%s",str);     //Statistics string length      int L;     L=strlen(str);//Need to include the header file #include<string.h>, use scanf to input the string, strlen cannot count spaces here.     printf("%d",L); */

    
 



    




// The second input method, gets() can input spaces, and printf can output spaces, the header file #include<string.h> can be added or not. 
    
    gets(str);
    printf("%s", str) ;
    
    int L;
    L=strlen(str);//Statistic character length, for the string input by gets(), spaces can be counted 
    printf("%d",L);
    
//Output can use puts() function, It can also output spaces, the header file #include<string.h> can be added or not. 
    gets(str);
    puts(str);
    
    
    return 0;
}
// I am new to programming, if there is any mistake, please correct me 
//Not complete, follow-up supplement 

Guess you like

Origin blog.csdn.net/qq_58136559/article/details/125173105