strdup ()函数

  原型:extern char *strdup(char *s);
  用法:#include <string.h>
  功能:复制字符串s
  说明:返回指向被复制的字符串的指针,所需空间由malloc()分配且可以由free()释放。
  举例:
  // strdup.c
  #include <syslib.h>
  #include <string.h>
  main()
  {
  char *s="Golden Global View";
  char *d;
  clrscr();
  d=strdup(s);
  printf("%s",d);
  free(d);
  getchar();
  return 0;
  }
      

   运行结果:

    Golden Global View

原文地址:https://www.cnblogs.com/eagleking0318/p/6521293.html