C language gets problem

I found that after gets read the string, it reads a newline at the end! , I don’t know how to solve it

The following is a test example: 

#include<stdio.h>
#include<string.h>
 
int main()
{
    char a[30];
    
    int i, a_len;
    
    gets(a);
 
    a_len = strlen(a);
 
    for(i=0; a[i]!='\0'; i++)
        printf("这是第%d个字符:%c\n", i, a[i]);
        
    printf("字符串长度为:%d\n", a_len);
 
}
 


Figure

Guess you like

Origin blog.csdn.net/sdaujz/article/details/111661287