我该如何分配繁琐重复的值到一个数组? [英] How do I assign cumbersome repetitive values to an array?
本文介绍了我该如何分配繁琐重复的值到一个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个10×10的阵列,其中包含。
的每个元素。所以,我写的是:
I want to create an array of 10 × 10, which contains '.'
for each element. So I write as :
int A[10][10]={ '.','.','.','.',
(等一下我必须写100句号和逗号100)
(wait a minute I have to write 100 full stops and 100 commas)
'.','.','.'}
另一种方法是写。
10次,然后复制粘贴10次,但仍需要时间,我不认为这是最聪明方法。
Another method is to write '.',
10 times and then copy paste it 10 times, but still this takes time and I don't think this is the smartest method.
有一个更聪明的方法是什么?我不想写那么长的句号。
Is there a smarter method? I don't want to write so long full stops.
推荐答案
唯一可行的办法的 初始化 的这样一个数组,是通过洪水(不幸)宏:
The only feasible way to initialize an array like this, is (unfortunately) by using a flood of macros:
#define ONE_DOT '.',
#define TWO_DOTS ONE_DOT ONE_DOT
#define FIVE_DOTS TWO_DOTS TWO_DOTS ONE_DOT
#define TEN_DOTS { FIVE_DOTS FIVE_DOTS },
#define TWENTY_DOTS TEN_DOTS TEN_DOTS
#define FIFTY_DOTS TWENTY_DOTS TWENTY_DOTS TEN_DOTS
#define ONE_HUNDRED_DOTS FIFTY_DOTS FIFTY_DOTS
int A[10][10] = { ONE_HUNDRED_DOTS };
这篇关于我该如何分配繁琐重复的值到一个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文