Hi folks,
Trying to create a macro that sums the elements of an integer array. This is the code so far, and I'm receiving some errors here...
Code:
#include <stdio.h>#include <string.h>
#include <stdlib.h>
#pragma warning(disable: 4996)
#define ARRAY_SIZE 10
#define SUMMARY (arrayOne) { \
int sum = 0; \
for (int c = 0; c <= ARRAY_SIZE - 1; c++) { \
sum += (arrayOne[c]); \
} \
printf("The sum of this array (1-10) is: %d", sum); \
} \
int main()
{
int arrayOne[ARRAY_SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
SUMMARY(arrayOne);
system("pause");
return 0;
}
I'm receiving these errors:
Code:
Error (active) E0065 expected a ';' Line 23
Error C2062 type 'int' unexpected Line 23
Error C2065 'sum': undeclared identifier Line 23
Is this because I need to be working with pointers when I'm passing the array to the directive SUMMARY, or am I not using parenthesis properly in the directive? Hhmm...