2014-02-17 2 views
0

DEVC++ v5.5.2에서 다음 코드를 실행하려고합니다. 다음 오류 "호환되지 않는 포인터 유형에서 반환"은 "return arr"헤더 파일에 속합니다. 또 다른 오류는 "결과 [0] [j] = CircularShift (arr);"라는 줄에 'double complex *'유형에서 'double complex'유형을 할당 할 때 호환되지 않는 유형입니다. 주 프로그램의C : 함수에서 반환 된 행렬

이 문제를 해결하는 데 도움주세요. 유형에서 '이중 복잡한'입력 할당 할 때> "호환되지 않는 유형 -

사전

선 위에 실행될 때이 오류가 팝업

enter code here 
#include<stdio.h> 
#include<conio.h> 
#include<stdlib.h> 
#include"complex.h" 
#include"shiftcheck.h" 
#define SIZE 6 
double complex *CircularShift(double complex arr[1][SIZE]); 
void display(double complex arr[1][SIZE]); 
int main() 
{ 
int no,i,j; 
    double complex (*result)[839],*result1; 
    double complex arr[1][SIZE]={2,3,4,1,8,9,}; 
    printf("\nHow many times do you want the array to perform circular shifting?\n"); 
    scanf("%d",&no); 

    for(j=0;j<no;j++) 
    result[0][j] = CircularShift(arr); 

/main.c의 코드에 감사드립니다 '이중 복잡한'*/

for(i=0;i<SIZE;i++) 
{ 
    printf("%.2f+%.2fi\t",creal(result[0][i]),cimag(result[0][i])); 

} 
printf("\n"); 
getch(); 
return 0; 
} 

헤더 파일

을 다음과 같다
#include<stdio.h> 
#include<conio.h> 
#include"complex.h" 
#define SIZE 6 
void display(double complex arr[1][SIZE]); 
double complex *CircularShift(double complex arr[1][SIZE]) 
{ 
    double complex temp[1][1]; 
temp[0][0] = arr[0][SIZE-1]; 
int i;//put the last element in the temp variable 
    for(i=SIZE-1;i>0;i--)//shift each value to the next value so that a hole can be   created in the beginning 
    arr[0][i]=arr[0][i-1];//shift the values,index 0 is not changed 
    arr[0][0]=temp[0][0]; 
    //display(arr); 
    return arr;/* the error in this line is "return from incompatible pointer type"*/ 
} 
+0

오류가 포함 된 것을 잊어 버렸습니다. – bengoesboom

+2

참고 : [헤더 파일에 비 인라인 함수 삽입 금지] (http://stackoverflow.com/questions/6068292/rules-of-thumb-for-putting-functions- 인 헤더 파일). 이 헤더를 둘 이상의 파일에 포함 시키려면 CircularShift 함수의 정의에 대한 인스턴스가 둘 이상있을 것이고 컴파일러는 모호한 것으로 간주 할 것입니다. '.h' 파일에서 함수를 프로토 타입 화하고'.c' 파일에 함수를 구현해야합니다. – HostileFork

+0

'result [0] [j]'는 포인터가 아닙니다. 그러나'CircularShift (arr); 리턴 포인터. 반환 값은 필요 없으며 배열의 내용을 변경하기 때문에 반환 값은 필요하지 않습니다. – BLUEPIXY

답변

0

당신의 complex.h 파일에 #include 가드를 착용 할 것 (그래서 한 번만 포함됩니다) :

#ifndef COMPLEX_H 
#define COMPLEX_H 
<insert complex.h stuff here> 
#endif 

그런 다음 main.c에서 함수 선언을 제거; 이미 shiftcheck.h에 정의했습니다.

관련 문제