0

I'm trying to run the following code in DEVC++ v5.5.2 The following error "return from incompatible pointer type" shows up in line "return arr" belonging to header file. Another error is "incompatible types when assigning to type 'double complex' from type 'double complex*" in the line that reads "result[0][j] = CircularShift(arr);" of the main program.

Please help me resolve this.

Thank you in advance

The main.c code

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);

/this error pops up when above line is executed ->"incompatible types when assigning to type 'double complex' from type 'double complex'*/

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

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

the header file is as follows

#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"*/
}
BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • You've forgotten to include the error – bengoesboom Feb 17 '14 at 05:34
  • 2
    Note: [Avoid putting non-inline functions in header files](http://stackoverflow.com/questions/6068292/rules-of-thumb-for-putting-functions-in-header-files). If you were to include that header in more than one file, there'd be more than one instance of a definition of the `CircularShift` function, and the compiler would consider it ambiguous. You should only prototype the functions in the `.h` files, and then implement them in `.c` files. – HostileFork says dont trust SE Feb 17 '14 at 05:42
  • `result[0][j]` isn't pointer. but `CircularShift(arr);` return pointer. There is no need for the return value and because they change the contents of the array. – BLUEPIXY Feb 17 '14 at 08:11
  • http://stackoverflow.com/questions/16004668/c-allocating-a-matrix-in-a-function/27366086#27366086 Above you will find a program that I have made with functions allocating and manipulating matrices in any possible way for C (gcc C11/C99). Maybe it will be useful for you... – 42n4 Dec 08 '14 at 20:21

1 Answers1

0

Put #include guards in your complex.h file (so it gets included only once):

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

Then remove the function declarations in main.c; you've already defined them in shiftcheck.h.

bb94
  • 1,294
  • 1
  • 11
  • 24