简体   繁体   English

清除2D字符数组

[英]Clear a 2d char array

I would like to ask if there is any fast way(using memset for example) to clear a char table like 我想问一下是否有任何快速的方法(例如,使用memset)来清除char表,例如

char mytable[2][10];

For example as I know using memset 例如我知道使用memset

memset(mytable, 0, sizeof(mytable));

is used for 1D tables. 用于一维表。

They're called arrays, not "tables". 它们被称为数组,而不是“表”。

And the very same code works for any array with arbitrary number of dimensions. 同样的代码适用于任意维数的数组。

What you have written will work for 2-D table as well. 您编写的内容也适用于二维表。 Actually it will work for any dimension of the array(assuming you are memset-ing a static array) 实际上,它将适用于数组的任何维度(假设您正在设置静态数组)

you can use pointer : 您可以使用指针

register int i ; 登记我;

const int max = MAXROW * MAXCOL ; const int max = MAXROW * MAXCOL;

char *p = &mat[0][0] ; char * p =&mat [0] [0];

for (i=0; i < MAXROW * MAXCOL ; i++) 对于(i = 0; i <MAXROW * MAXCOL; i ++)

*p++ = 'x' ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM