Good evening,
I have a problem with macros. I am supposed to come up with a macro ENTRY
, that puts a value into an array ( scanf("%d",&ENTRY(x,i))
was given).
I tried: #define ENTRY (a,b) (a[b-1])
, but that didn't work.
It created a compiler error that says, that a and b are undeclared.
But I thought that I don't have to declare variables used in macros, especially because, for example: #define min (a,b) ((a)<(b)?(a):(b))
worked in another program.
So what am I doing wrong here?
#include <stdio.h>
#define N 3
#define ENTRY (a,b) (a[b-1])
int main(void)
{
int x[N],i;
float y[N];
for(i=1;i<=N;i++){ printf("x_%d = ",i);scanf("%d",&ENTRY(x,i));}
for(i=1;i<=N;i++){ printf("y_%d = ",i);scanf("%lf",&ENTRY(y,i));}
return 0
}