gpt4 book ai didi

c++ - for 每个循环读取数组都是错误的

转载 作者:行者123 更新时间:2023-11-30 18:41:24 25 4
gpt4 key购买 nike

我知道我比这个更好。

但是每次我运行数组时,它不是从 1 到 5 开始,而是从 49 开始。我不知道为什么,但这开始变得烦人。

我确信这很简单,但我现在不知道如何做。我想要做的是运行 foreach 循环并打印出数组的该部分。
然后我想测试 Status[]。

状态应仅在条件合适时打印测试编号。测试数 = arr[i]

int main(void)
{
char status[10];
int test1 = 0, test2 = 0, test3 = 0, test4 = 0;
int arr[] = {'1','2','3','4','5'};
int value[] = { '1','2','3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25'};




for (int i = 0; i < 5; i++)
{
printf(" \n %i# %i \n", i, arr[i]);


}

printf("test S: %i \n", test1);
printf("test MS: %i \n", test2);
printf("test MJ: %i \n", test3);
printf("test SH: %i \n", test4);

system("pause");

}

更新:抱歉,我的意思是我读错了。它不是读取和写入 1 2 3 4 5,而是显示 49 50 等等

最佳答案

字符'1'的值在您的系统上显示为49。数字字符在解释 50 等的任何编码中都是连续的。

也许您的意思是:int arr[] = {1,2,3,4,5};

关于c++ - for 每个循环读取数组都是错误的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21947252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com