小编Yee*_*Kee的帖子

将主数据转换为全局数据,以后由主数据库进行修改?

我有两个字母数组,格式如下:

const char plain[26] = {'a','b',....'y','z'} // this is the the full alphabet
const char crypt[26] = {'i','d',....'m','x'}; // this is the the alphabet scrambled
Run Code Online (Sandbox Code Playgroud)

两个数组中的字母顺序可以根据输入而改变.此更改发生在main函数中.

这样做的目的是将字符串的字母与第二个字母匹配,就像加密一样.我将字符与数组值进行比较.所以它看起来像这样(简化)

text[3] = 'yes';
changed[3];
if(text[0] == plain[25]){    //would be done under a for loop so 25 would be a changing integer value
    changed[0] = [crypt[25];
}
Run Code Online (Sandbox Code Playgroud)

我的代码完全在main函数下工作.我想提到这样的目的,因为我之前的问题只是由于数组和格式的类型.由于数组被移到外面,我可能会再次遇到这些问题.


现在我想让数组全局化.实际加密发生在不将数组作为变量的函数中.但我希望该功能可以访问它们.

这就是它现在的样子

const char plain[26];
const char crypt[26];
int maint(void){
    const char plain[26] = {'a','b',....'y','z'} \\values get changed here 
    const char crypt[26] = {'i','d',....'m','x'} \\and here …
Run Code Online (Sandbox Code Playgroud)

c arrays global-variables

9
推荐指数
1
解决办法
651
查看次数

标签 统计

arrays ×1

c ×1

global-variables ×1