如何在C中声明常量2D字符串数组 [英] How to declare a constant 2d string array in C

查看:77
本文介绍了如何在C中声明常量2D字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下数组结构:

left , right , top
top , left , right 
top , top , left 

我想在C中声明它,我已经这样做了:

I want to declare it in C , I have done it like this :

char *movements[][] = {{"left","right","top"},
                        {"top","left","right"},
                        {"top","top","top"}
                       }

但是我遇到了这个错误:数组的元素类型不完整.什么是实现此目的的正确方法(声明和访问(打印)).我必须采用三维数组吗?

But I am getting this error : array has incomplete element type. What is the right way of achieving this(declaring and accessing (printing)).Do I have to take three dimensional array?

推荐答案

在C中,定义二维数组时必须指定列大小.看一下这个问题:

In C, you have to specify the column size when defining a two dimensional array. Take a look at this question: Why do we need to specify the column size when passing a 2D array as a parameter?

char *movements[][3] = {
                           {"left","right","top"},
                           {"top","left","right"},
                           {"top","top","top"}
                       };

这篇关于如何在C中声明常量2D字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆