nostrum, are you going through the Practical C Programming book by O'Reilly? If so, I am too and did my a little different.
For the variables i made them float instead of double to save memory, and my math was done a little different.
I did:
Code:
/*This program will find the distance between two points on a grid*/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
char line[10];/*input data to be converted*/
float xcoordf;/*first X coordinate*/
float ycoordf;/*first Y coordinate*/
float xcoords;/*second X coordinate*/
float ycoords;/*second Y coordinate*/
float xanswer;/*difference in X coordinates*/
float yanswer;/*difference in Y coordinates*/
float answer;/*average of the difference in both coordinates*/
main()
{
(void)printf("Distance between two points.\n
Enter the first x,y coordinates(using this format, no commas: x1 y1):");
(void)fgets(line,sizeof(line),stdin);
(void)sscanf(line,"%f %f",&xcoordf,&ycoordf);
(void)printf("Enter the second set of coordinates(x2 y2, no commas):");
(void)fgets(line,sizeof(line),stdin);
(void)sscanf(line,"%f %f",&xcoords,&ycoords);
xanswer=(xcoords-xcoordf)*(xcoords-xcoordf);
yanswer=(ycoords-ycoordf)*(ycoords-ycoordf);
answer=sqrt(xanswer+yanswer);
(void)printf("The difference in the two points is %.2f.\n",answer);
return(0);
}
Was running into the same brickwall as you until I linked to libmath under the suggestion of backer. Compiles and links with no errors or warnings of any kind.
Before I picked up
Practical C Programming I was using
C For Dummies, that book really walked you along slowly. I do not recommend it for anyone with a working knowledge of computers.