2017-06-03 47 views
-2
int input,n,i; 
    scanf("%d%d",&input,&n); 
    double a,b; 
    double complex arr[n]; 

     for (i = 0; i < n; ++i) 
     { 
     scanf("%lf%lf",&a,&b); 
     creal(arr[i])=a; 
     cimag(arr[i])=b; 
     } 

誤差:必須爲分配enter code here creal的左操作數的左值(ARR [I])= A; 爲什麼我不能拿輸入的複數如何掃描的複數陣列用C

+1

什麼是'creal'和'cimage'? – Mureinik

+0

哦,等等,你的意思是[這些](http://en.cppreference.com/w/c/numeric/complex/creal)? – Mureinik

+1

'arr [i] = CMPLX(a,b);' – EOF

回答

0

6.2.5p13,你可以做一個陣列(未測試!)

double complex a[42]; 
double tmp[2]; 
tmp[0] = 3.14159; 
tmp[1] = -2.71828; 
memmove(a + 3, tmp, sizeof tmp); // a[3] = 3.14159 - 2.71828i 
+0

而不是直接分配,你可以當然這樣做:'if(scanf(「%lf%lf」,tmp,tmp + 1)!= 2)/ * error * /;' – pmg