鱼C论坛

 找回密码
 立即注册
查看: 2784|回复: 5

strcat的问题

[复制链接]
发表于 2019-6-4 16:18:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include <stdio.h>
#include <string.h>
#define SIZE 80
char * s_gets(char *st, int n);
int main(void)
{
        char flower[SIZE];
        char addon[] = "s smell like old shoes.";

        puts("What is your favorite flower?");
        if (s_gets(flower, SIZE))
        {
                strcat(flower, addon);
                puts(flower);
                puts(addon);
        }
        else
                puts("End of file encountered!");
        puts("bye");

        getchar();
        return 0;
}

char * s_gets(char*st, int n)
{
        char * ret_val;
        int i = 0;

        ret_val = fgets(st, n, stdin);
        if (ret_val)
        {
                while (st[i] != '\n' && st[i] != '\0')
                        i++;
                if (st[i] == '\n')
                        st[i] = '\0';
                else
                        while (getchar() != '\n')
                                continue;
        }
        return ret_val;
}


这个程序中出现了        'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.        str_cat        h:\c primer plus\c11\str_cat\str_cat\str_cat.c        13        ,怎样解决
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2019-6-4 16:20:44 | 显示全部楼层
windows下面使用 strcat_s 或者添加一个宏去除警告,具体你要百度一下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-6-4 16:43:35 | 显示全部楼层
使用strcat_s,不然你就在程序开头加上
#deine _CRT_SECURE_NO_WARNINGS
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-6-4 18:47:40 | 显示全部楼层
提示信息说的很明白了
'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
函数strcat可能不安全,考虑用strcat_s替换,或者使用_CRT_SECURE_NO_WARNINGS禁止报错。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-6-4 23:05:52 | 显示全部楼层
shake_a_tree@16 发表于 2019-6-4 18:47
提示信息说的很明白了
'strcat': This function or variable may be unsafe. Consider using strcat_s in ...

我用strcat_s的时候,他说缺少参数
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-6-8 13:52:59 | 显示全部楼层
hickttye 发表于 2019-6-4 23:05
我用strcat_s的时候,他说缺少参数

缺参数就加呀,或者用_CRT_SECURE_NO_WARNINGS宏定义。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-3 21:30

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表