以下是引用梨花压海棠在2020-2-14 11:15:00的发言:
错误 C4996 'strncat': This function or variable may be unsafe. Consider using strncat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. API E:\Project\C\shujujiegou\API\API\pr_倒转str.c 31
这是没加_s的错误
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void inverse(char *p);
void inverse01(char *p, char *result);
void main()
{
char buf[] = "abcde";
char mybuf[1024] = { 0 };
inverse(buf);
inverse01(buf, mybuf);
}
void inverse(char *p)
{
if (p == NULL)
return;
if (*p == '\0')
return;
inverse(p+1);
printf("%c", *p);
}
void inverse01(char* p,char* result)
{
if (p == NULL||result==NULL)
return;
if (*p == '\0')
return;
inverse(p + 1,result);
strncat_s(result, p, 1);
}
这是我改了形参的代码,还是提示一样的问题,应该是我strncat这个函数没搞明白,但是用法我也看不懂,视频上也就是这样写的,
errno_t strncat_s(char * restrict dest,rsize_t destsz,const char * restrict src,rsize_t count);
我没注释的地方你就不会改了
程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void inverse(char *p);
void inverse01(char *p, char *result);
void main()
{
char buf[] = "abcde";
char mybuf[1024] = { 0 };
inverse(buf);
inverse01(buf, mybuf);
}
void inverse(char *p)
{
if (p == NULL)
return;
if (*p == '\0')
return;
inverse(p+1);
printf("%c", *p);
}
void inverse01(char* p,char* result)
{
if (p == NULL||result==NULL)
return;
if (*p == '\0')
return;
inverse01(p + 1,result);//加个01
strncat(result, p, 1);
}