美文网首页
不建议使用scanf作输入函数

不建议使用scanf作输入函数

作者: 一个冬季 | 来源:发表于2018-06-07 21:02 被阅读6次
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    int main(void) {
        char buf[100]={0};
        printf("请输入字符串:");
        scanf("%s",buf);
        printf("buf=%s\n",buf); 
        
        char tmp[100]={0};
        printf("请输入字符串:");
        scanf("%s",tmp);
        printf("tmp=%s\n",tmp); 
        //这里如果你输入的超过了10个,不同编译器不同
      //当你超过10个有些会报错,有些编译器不会报错
        char str[10]={0};
        printf("请输入字符串:");
        scanf("%s",str);
        printf("str=%s\n",str); 
        
        printf("\n");
        system("pause");
        return 0;
    }
    

    这里不建议使用scanf作输入函数,因为他不安全,他不会对输入的进行检查

    相关文章

      网友评论

          本文标题:不建议使用scanf作输入函数

          本文链接:https://www.haomeiwen.com/subject/gnrusftx.html