Anum Sheraz Anum Sheraz - 3 months ago 8
C Question

create a list of array in C

I am trying to create a list like:

[(0, 100), (1, 200), (2, 300), (3, 400), (4, 450), (5, 500), (6, 550), (7, 560), (8, 570)]


I made it in python by simply zipping two list;

x = [0,1,2,3,4,5,6,7,8]
y = [100,200,300,400,450,500,550,560,570]

zipit = zip(x,y)


What is the best way to do the same in Arduino C?

Answer

Use struct that holds 2 ints and make an array out of it:

struct pair {int a; int b;} arr[100];
void setup() {
  //creating simple [(5,6), (1,2)]
 arr[0].a = 5;
 arr[0].b = 6;

 arr[1].a = 1;
 arr[1].b = 2;
}

void loop() {
  // put your main code here, to run repeatedly:

}