I am trying to pass a struct of array to a function without a pointer.
I'm trying to pass an array[], so it will print the next value of the array.
The code below has an array of List[5] = {1,2,3,4}, where the first int in the array
will be processed in
struct Count numbers()
I included the increment i, so the printCode() will print integers of
numbers.intOne[1] & numbers.intTwo[1], numbers.intOne[2] & numbers.intTwo[2] etc...
I want the program to run the array one by one, for example 1 will be added by 4 and added by 6, which will print 57. And the next value will be 2, which will result in 6 and 8. But it will only take the same value from the struct and keeps printing 575757.
How can I make the function continue to the next array value (and print 58), and is this possible without an array?
What I have tried:
#include <stdio.h>
struct Count {
int intOne;
int intTwo;
};
struct Count numbers() {
struct Count numbers;
int List[5] = { 1, 2, 3, 4 };
int i;
for (i = 0; i < 10; i++) {
numbers.intOne = List[i] + 4;
numbers.intTwo = List[i] + 6;
return numbers;
}
};
void printCode(struct Count numbers) {
int i;
for (i = 0; i < 2; i++) {
printf("%i%i", numbers.intOne, numbers.intTwo);
}
}
int main() {
int i = 0;
for (i = 0; i < 10; i++) {
numbers();
printCode(numbers());
getchar();
}
}