小编Ran*_*shi的帖子

使用带有字符指针的 strcat 函数

我想通过使用两个字符指针来打印“Hello - World”,但我有一个“分段错误(核心转储)”问题。

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define Hyphen " - "
int main()
{
  char* x="Hello";
  char* y="'World'";
  strcat(x, Hyphen);
  strcat(x, y);
  printf("%s",x);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

c pointers string-literals strcat

5
推荐指数
1
解决办法
2042
查看次数

标签 统计

c ×1

pointers ×1

strcat ×1

string-literals ×1