C Primer Plus (第6版)中文版 P303中程序清单11.26 copy2.c程序,运行有问题,麻烦各位,怎么修改才不会有错误
#include <stdio.h>
#include <string.h>
#define WORDS "beast"
#define SIZE 40
int main(void)
{
const char* orig = WORDS;
char copy[SIZE] = "Be the best that you can be.";
char* ps;
puts(orig);
puts(copy);
ps = strcpy_s(copy + 7, 50, orig);
puts(copy);
puts(ps);
return 0;
}
你确定是这样的代码?很多问题好吧。strcpy_s返回值是errno_t(int)类型,不能赋值给char*指针。
你想要的代码可能是这样?
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#define WORDS "beast"
#define SIZE 40
int main(void)
{
const char* orig = WORDS;
char copy[SIZE] = "Be the best that you can be.";
char* ps;
puts(orig);
puts(copy);
ps = strcpy(copy + 7, orig);
puts(copy);
puts(ps);
return 0;
}