めも

C言語で二次元配列について聞かれたのでちょっとサンプル作ってみたので備忘のためにメモ。


int main(int argc, char **argv){
/* エリアの初期化 */
char array[5][10] = {"rx-78","rx-78-2","rx-78-3","rx-178","msz-006"};
/* 内容の表示 */
int i = 0;
for(i = 0; i < 5; i++){
fprintf(stderr,"hoge:%s\n",array[i]);
}
/* クリア */
memset(array,'\0',50);
/* 新しい値の設定 */
strcpy(array[0],"ms-05");
strcpy(array[1],"ms-06");
strcpy(array[2],"ms-07");
strcpy(array[3],"ms-09");
strcpy(array[4],"ms-14");
/* 内容の表示 */
for(i = 0; i < 5; i++){
fprintf(stderr,"hoge:%s\n",array[i]);
}

return 0;
}

 これでほぼ思うとおりの結果がでたのですが、

memset(array,'\0',50);
 これはありなのか…ちょっと不安。