#include <stdio.h>
#include<stdlib.h>
typedef struct complex {
int real;
int imag;
} complex;
complex n1, n2;
complex add(complex n1, complex n2) {
complex temp;
temp.real = n1.real + n2.real;
temp.imag = n1.imag + n2.imag;
printf("%d+%di",temp.real,temp.imag);
return (temp);
}
complex sub(complex n1,complex n2)
{
complex temp;
temp.real = n1.real - n2.real;
temp.imag = n1.imag - n2.imag;
printf("%d+%di",temp.real,temp.imag);
return (temp);
}
complex mul(complex n1,complex n2)
{
complex temp;
temp.real = (n1.real * n2.real)-(n1.imag * n2.imag);
temp.imag = (n1.real*n2.imag)+(n1.imag * n2.real);
printf("%d+%di",temp.real,temp.imag);
return (temp);
}
void c(complex n1,complex n2,void(*ptr)(complex,complex))
{
(*ptr)(n1,n2);
}
int main()
{
int choice;
printf("For 1st complex number \n");
printf("Enter the real and imaginary parts: ");
scanf("%d %d", &n1.real, &n1.imag);
printf("\nFor 2nd complex number \n");
printf("Enter the real and imaginary parts: ");
scanf("%d %d", &n2.real, &n2.imag);
printf("which operation can do:");
scanf("%d",&choice);
switch(choice)
{
case 1:
c(n1,n2,&add);
break;
case 2:
c(n1,n2,&sub);
break;
case 3:
c(n1,n2,&mul);
break;
default:
printf("bye enter the choice btw 1-3");
break;
}
return 0;
}
This is the warning from the compiler:
warning: incompatible function pointer types passing 'complex (*)(complex, complex)'
(aka 'struct complex (*)(struct complex, struct complex)') to parameter of type
'void (*)(complex, complex)' (aka 'void (*)(struct complex, struct complex)')
[-Wincompatible-function-pointer-types]