hickttye 发表于 2019-6-4 16:18:31

strcat的问题

#include <stdio.h>
#include <string.h>
#define SIZE 80
char * s_gets(char *st, int n);
int main(void)
{
        char flower;
        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 != '\n' && st != '\0')
                        i++;
                if (st == '\n')
                        st = '\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        ,怎样解决

Krant5 发表于 2019-6-4 16:20:44

windows下面使用 strcat_s 或者添加一个宏去除警告,具体你要百度一下

Croper 发表于 2019-6-4 16:43:35

使用strcat_s,不然你就在程序开头加上#deine _CRT_SECURE_NO_WARNINGS

shake_a_tree@16 发表于 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禁止报错。

hickttye 发表于 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的时候,他说缺少参数

shake_a_tree@16 发表于 2019-6-8 13:52:59

hickttye 发表于 2019-6-4 23:05
我用strcat_s的时候,他说缺少参数

缺参数就加呀,或者用_CRT_SECURE_NO_WARNINGS宏定义。
页: [1]
查看完整版本: strcat的问题