Functions that return structures
I've been trying to create a code that includes structures produced at various event times by a function. Since it was clear that my structure-producing function was not working, I decided to try building a very simple code that just produces a structure from a function.
Not surprisingly, it doesn't work either. It returns an error saying "funs returning structs/unions illegal '=makepoint(1,1)' ".
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
struct point {
int x;
int y;
};
struct point makepoint(int a, int b);
int main() {
struct point point1;
point1=makepoint(1,1);
printf( "done" );
getchar();
return 0;
}
struct point makepoint(int a, int b) {
struct point new;
new.x=a;
new.y=b;
return new;
}
I presume I'm making a really elementary coding error. :confused: