gpt4 book ai didi

C:从函数返回矩阵

转载 作者:行者123 更新时间:2023-11-30 17:39:24 24 4
gpt4 key购买 nike

我正在尝试在 DEVC++ v5.5.2 中运行以下代码以下错误“从不兼容的指针类型返回”显示在头文件的“return arr”行中。另一个错误是“当从类型‘double complex*’分配给类型‘double complex’时,类型不兼容”,在“result[0][j] = CircularShift(arr);”行中主程序。

请帮我解决这个问题。

提前谢谢

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

/执行上述行时会弹出此错误 ->“从类型“双复杂”分配给类型“双复杂”时出现不兼容的类型”*/

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"*/
}

最佳答案

#include 守卫放入您的 complex.h 文件中(这样它只包含一次):

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

然后删除main.c中的函数声明;您已经在 shiftcheck.h 中定义了它们。

关于C:从函数返回矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21821473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com