清除char**中的内容

标签 c char

对于我的一生,我不知道如何做到这一点。我想我可以使用 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 ) 这样的 while 循环将每个元素设置为 0,但即使这样我也会遇到段错误。这应该很容易吧?我做错了什么?

最佳答案

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

检查引用:

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

您到底想要实现什么目标?

关于清除char**中的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14776913/

相关文章:

c - 函数原型(prototype)声明 c

c - 为什么这个 while 条件没有捕获 EOF?我遇到段错误

c++ - MSVC 中的不透明指针会生成编译器错误

我可以同时写入两个不同的 FILE 指针吗?

c++ - 在 C++ 字符中存储 unicode

c - 用 C 中充满数字的 char 数组填充 int 数组(char 数组到 int 数组)

Java Hangman 代码,char 数组

c++ - 当字符串从函数返回时,如果在它之前有和结束行,它会错误地打印输出

c++ - MSVC 相当于 __attribute__ ((warn_unused_result))?

c++ - 如何修复这个: Argument of type “const char*” is incompatible with the parameter of type "char** [duplicate]