I'm learning how to use structures in C, and I'm not sure how to scanf user input into a structure... Here's the structure:
typedef struct {
double x,y;
char name; // MUST BE SINGLE UPPERCASE LETTER
} pointType;
typedef struct {
pointType A, B; // line segment defined by two points
int slopeDefined; // 1 if slope is defined and 0 in undefined
double slope; // rise/run = y2-y1 / x2-x1
}lineSegType;
Here's the code I'm using to try and copy user input into those fields in the structure:
void getPoint (pointType *P){
printf("Enter your x-coordinate: ");
scanf("%lf",&P->x);
printf("Enter your y-coordinate: ");
scanf("%lf",&P->y);
}
void getLineSeg (lineSegType *lSeg){
printf("Enter first point name (single uppercase letter): ");
scanf("%c",&lSeg->A.name);
getPoint(&lSeg->A);
printf("Enter second point name (single uppercase letter): ");
scanf("%c",&lSeg->B.name);
getPoint(&lSeg->B);
}
The program skips the "printf("Enter first point name (single uppercase letter): ");" and "printf("Enter second point name (single uppercase letter): ");" and doesn't copy the user entered coordinates to the x and y fields in the structure :/