strcpy

您所在的位置:网站首页 strcpy和strcpy_s strcpy

strcpy

2023-09-23 05:37| 来源: 网络整理| 查看: 265

正确用法:

  int n = 6;  char **argsmy = new char *[n];  int maxlen = 600;  for(int i = 0; i < n; i ++)  {    argsmy[i] = new char [maxlen];// args[i];  }   strcpy_s(argsmy[1],maxlen,"e");  strcpy_s(argsmy[2],maxlen,"Lzma_");  strcat_s(argsmy[2], 600, cTAppEncTop.getBitstreamFile());  strcpy_s(argsmy[3],maxlen,"-BS12");  strcpy_s(argsmy[4],maxlen,"-CN0");  strcpy_s(argsmy[5],maxlen,"-d15");

 

 

错误用法:

argsmy[2] = "Lzma_"; strcpy_s(argsmy[2],maxlen,"see");

原因:

argsmy[2] = "Lzma_"; //因为 argsmy[2] 是个指针。他指向一块分配的空间 ,长度 maxlen。

而这样赋值后,指针指向位置变了。而再strcpy_s(argsmy[2],maxlen,"see"); 实际上是将常数变量空间强制赋值。因此出问题。

 

 

 

 

 

strcpy_s 用法:

 

errno_t strcpy



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3