c_cpp c中的基本字符串复制

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp c中的基本字符串复制相关的知识,希望对你有一定的参考价值。

#include "stdio.h"
#include "string.h"
#include "stdlib.h"

//string examples for c

int main(void) {
  const char* a = "foobeans";
  int len = strlen(a);
  char* b = malloc(len);
  strcpy(b, a);
  puts(b);
  return 0;
}

以上是关于c_cpp c中的基本字符串复制的主要内容,如果未能解决你的问题,请参考以下文章