为什么vscode报错了,如何解决?(语言-c语言)

这运行不了

#include 
#include 

typedef struct {
    float realpart;
    float imagpart;
    
}complex;
complex* assign(complex* A, float real, float imag);
int main()
{
    
    complex* z;
    z = (complex*)malloc(sizeof(complex));
    
    assign(&z, 3.0, 1.0);

    printf("%f+%fi\n", z->realpart, z->imagpart);
    free(z);

    system("pause");
}
complex* assign(complex *A, float real, float imag)
{
    A->realpart = real;
    A->imagpart = imag;
    return A;

}

在您的代码中,assign函数的参数类型应该是complex*而不是complex**。因此,您应该将函数调用的参数更改为assign(z, 3.0, 1.0)而不是assign(&z, 3.0, 1.0)。此外,您也需要包含头文件<conio.h>来使用system函数。修改后的代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

typedef struct {
    float realpart;
    float imagpart;
} complex;

complex* assign(complex* A, float real, float imag);

int main()
{
    complex* z;
    z = (complex*)malloc(sizeof(complex));
    assign(z, 3.0, 1.0);
    printf("%f+%fi\n", z->realpart, z->imagpart);
    free(z);
    system("pause");
}

complex* assign(complex* A, float real, float imag)
{
    A->realpart = real;
    A->imagpart = imag;
    return A;
}