gpt4 book ai didi

c - 如何迭代多个数组

转载 作者:行者123 更新时间:2023-11-30 16:20:26 24 4
gpt4 key购买 nike

如何在函数调用中迭代这 5 个数组?现在我只是手动迭代每个字符以形成特定的字符

    const unsigned char pattern1bar[8]={0x10,0x10,0x10,0x10,0x10,0x10,0x10};
const unsigned char pattern2bar[8]={0x18,0x18,0x18,0x18,0x18,0x18,0x18};
const unsigned char pattern3bar[8]={0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c};
const unsigned char pattern4bar[8]={0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e};
const unsigned char pattern5bar[8]={0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f};



void LCD_build(int custom, int cursor, const unsigned char *x,const unsigned char x2, int cgdisplay){
writeLCD(custom,0,0,1); // 1) set custom gram address location
unsigned char i;
for( i= 0; i <x2; i++)
writeLCD(x[i],1,0,1);
writeLCD(cursor,0,1,1); // 3) set cursor to location you want to write to
writeLCD(cgdisplay,1,1,1); // 4) display cgram(0x00) custom character at current cursor location
DELAY_MS(800);

};

//function call
LCD_build(0x40,0x80,pattern1bar,8,0x00);
LCD_build(0x40,0x80,pattern2bar,8,0x00);
LCD_build(0x40,0x80,pattern3bar,8,0x00);
LCD_build(0x40,0x80,pattern4bar,8,0x00);
LCD_build(0x40,0x80,pattern5bar,8,0x00);

最佳答案

下面是一个简单的解决方案,将 3 个整数数组放入一个二维数组中:

#include <stdio.h>
#define LENGTH 5

const unsigned short a1[] = {1, 4, 2, 4, 1};
const unsigned short a2[] = {3, 4, 2, 1, 2};
const unsigned short a3[] = {4, 12, 1, 1, 2};

void main()
{
const unsigned short *ar[] = {a1, a2, a3};
unsigned i, j;

for (i = 0; i < LENGTH; i++)
{
for (j = 0; j < LENGTH; j++)
{
printf("%d ", ar[i][j]);
}

printf("\n");
}
}

关于c - 如何迭代多个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55303693/

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