[Courses] Reminder, and questions (and semi spoiler on ex 6-1)
Michelle Murrain
tech at murrain.net
Mon Feb 25 09:54:21 EST 2002
Sorry, I've been remiss in my "coordination"! The next set of chapters, 4,5
and 6 were theoretically due last Friday! I've just now finished chapter 6.
How is it going? How is everyone doing? Post your progress to the list, so
people know what's up.
I have two questions for the gurus:
1) Why is forgetting the "\n" at the end of a printf statement suppress the
line altogether? ( in perl, it will simply print the line w/o a newline).
2) In trying to do exercise 1, I wanted to use the sqrt function. I looked
at the (short) man page for it. This is the code I have:
#include <stdio.h>
#include <math.h>
/* program to find the distance between two points */
int x1;
int x2;
int y1;
int y2;
char line[20];
int distance_squared;
double distance;
double sqrt(double distance);
int main()
{
printf("Point 1(x,y):");
fgets(line, sizeof(line), stdin);
sscanf(line, "%d,%d",&x1,&y1);
printf("Point 2(x,y):");
fgets(line, sizeof(line), stdin);
sscanf(line, "%d,%d",&x2,&y2);
printf("Here are the points:%d,%d and %d,%d\n",x1,y1,x2,y2);
distance_squared = ((x2-x1)^2) + ((y2-y1)^2);
distance = sqrt(distance_squared);
printf("Square of distance between two points: %d Actual distance:
%f\n",distance_squared,distance);
return(0);
}
On compiling, it barfs with this error:
/home/mpm/tmp/ccU4dc3d.o: In function `main':
/home/mpm/code/cprograms/ex6-1.c:26: undefined reference to `sqrt'
collect2: ld returned 1 exit status
So what am I doing wrong?
Thanks.
.Michelle
---------------------------------------
Michelle Murrain
tech at murrain.net
AIM/Yahoo Messenger:pearlbear0
http://www.murrain.net/ for pgp public key
More information about the Courses
mailing list