对于gets()的知识点补充

Introduce:

        gets() 函数的功能是从输入缓冲区中读取一个字符串存储到字符指针变量 str 所指向的内存空间。参数类型为 char* 型,即 str 可以是一个字符指针变量名,也可以是一个字符数组名。

Learn from:

gets函数,C语言gets函数详解_wowocpp的博客-CSDN博客_gets函数

函数gets()的用法_农夫阿才的博客-CSDN博客_gets函数

Detal:

#include<stdio.h>

int main(){
    char arr[10]="\0";
    gets(arr);
    printf("%s",arr);
    return 0;

}

Important:

gets() 函数算输入的字符串中有空格也可以直接输入

EX:

//查找指定字符串
#include<stdio.h>

int main()
{
    char arr[100]={0},find,ch=0;
    int i=0,j,k,index=-1;
    scanf("%c",&find);
    getchar();
    gets(arr);
    for(j=strlen(arr)-1;j>=0;j--){
        if(arr[j]==find){
            index=j;
            break;
        }
    }
    if(index>=0) printf("index = %d\n",index);
    else printf("Not Found\n");
    return 0;
}

Summary:

nothing

猜你喜欢

转载自blog.csdn.net/Crabfishhhhh/article/details/128907229
今日推荐