c - When I try to use scanf with 2 arrays I get an error -
i trying use scanf assign values 2 arrays, 1 x coordinate, , other 1 y, using code that:
for (i1=1;i1<n;i1++) { scanf ("%f%f",&(arx[i1], ary[i1])); }
but when execute error:
prog.c: in function ‘main’: prog.c:11:25: warning: left-hand operand of comma expression has no effect [-wunused- value] scanf ("%f%f",&(arx[i1], ary[i1])); ^ prog.c:11:16: error: lvalue required unary ‘&’ operand scanf ("%f%f",&(arx[i1], ary[i1]));
so don't know doing wrong here, new c
change
scanf ("%f%f",&(arx[i1], ary[i1])); // not valid syntax
to
scanf ("%f%f",&arx[i1], &ary[i1]);
you need apply &
operator each of arx[i1]
and ary[i1]
otherwise ,
in (arx[i1], ary[i1])
interpreted compiler comma operator , hence return r-value. , should know operand of unary &
must l-value.
Comments
Post a Comment