N
N Yiannakoulias
Hi all,
I'm playing around with structures and functions. This code
is flawed, and I think I need help understanding the problem.
Can anyone help?
#include <stdlib.h>
#include <stdio.h>
struct coordinates
{
int x;
int y;
};
struct coordinates *location(void)
{
struct coordinates *coord;
coord = malloc(sizeof(coord)*2);
/*should check for available resources...*/
coord[0].x = 10;
coord[0].y = 15;
coord[1].x = 5;
coord[1].y = 8;
return coord;
}
int print_values(struct coordinates *location_s)
{
printf("%d,%d\n",location_s[0].x,location_s[0].y);
printf("%d,%d\n",location_s[1].x,location_s[1].y);
return 0;
}
int main(void)
{
struct coordinates *location_s;
location_s=location();
print_values(location_s);
return 0;
}
N
I'm playing around with structures and functions. This code
is flawed, and I think I need help understanding the problem.
Can anyone help?
#include <stdlib.h>
#include <stdio.h>
struct coordinates
{
int x;
int y;
};
struct coordinates *location(void)
{
struct coordinates *coord;
coord = malloc(sizeof(coord)*2);
/*should check for available resources...*/
coord[0].x = 10;
coord[0].y = 15;
coord[1].x = 5;
coord[1].y = 8;
return coord;
}
int print_values(struct coordinates *location_s)
{
printf("%d,%d\n",location_s[0].x,location_s[0].y);
printf("%d,%d\n",location_s[1].x,location_s[1].y);
return 0;
}
int main(void)
{
struct coordinates *location_s;
location_s=location();
print_values(location_s);
return 0;
}
N