【问题标题】:clear contents in char** [closed]清除 char** 中的内容 [关闭]
【发布时间】:2013-01-24 11:24:24
【问题描述】:

对于我的生活,我无法弄清楚如何做到这一点。我以为我可以使用memset(),但我遇到了分段错误。

char **a;
token = strtok( NULL, " " );
if( token != NULL )
    strcpy( token, strtok( token, "\n" )); // get rid of '\n' at end if it exists
else{  
    // I want to reset all the values in a to null 
    return;
} 

我想我什至可以像while(a[i] != 0 ) 这样将每个元素设置为0 的while 循环,但即便如此我还是遇到了分段错误。这应该很容易吧?我做错了什么?

【问题讨论】:

标签: c char


【解决方案1】:

您对 strtok() 的初始调用不应使用 NULL 参数作为第一个参数!

检查参考:

http://www.cplusplus.com/reference/cstring/strtok/

你到底想达到什么目的?

【讨论】:

  • 抱歉,我只发布了一段不起作用的代码。
猜你喜欢
  • 1970-01-01
  • 2011-03-27
  • 2023-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-29
  • 1970-01-01
相关资源
最近更新 更多