Created
August 3, 2019 19:54
-
-
Save heronyang/fb0a644a81042a25c534a82ec810baf6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* point.h */ | |
struct Point; | |
struct Point* makePoint(double x, double y); | |
double getDistance(struct Point *p1, struct Point *p2); | |
/* point.c */ | |
#include "point.h" | |
#include <stdlib.h> | |
#include <math.h> | |
struct Point { | |
double x, y; | |
} | |
struct Point* makePoint(double x, double y) { | |
struct Point* p = malloc(sizeof(struct Point)); | |
p->x = x; | |
p->y = y; | |
return p; | |
} | |
double getDistance(struct Point* p1, struct Point *p2) { | |
double dx = p1->x - p2->x; | |
double dy = p1->y - p2->y; | |
return sqrt(dx*dx + dy*dy); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment