# Determining a Triangle using get and pointer

• 04-10-2003
naynay
Determining a Triangle using get and pointer
a. Define a struct data type to represent a triangle as 3 points.
b. Write a function get_triangle(), to input the three corners of a triangle and return triangle structure. Using triangle get_triangle()
c. Write a function classify(); that will analize the shape of triangle. The input should be one triangle and the result should be a pointer to a character array. Prototype is: char * classify triangle.
d. Write a main program with loop which will permit user to enter a series of triangles. For each echo the input, call the classify() fuction and print the triangles shape. (isosceles 2 sides equal, equilateral all sides same, or scalene no sides are equal).
The problem I am having so far is how call to classify and determine which shape it is.
#include <stdio.h>

typedef struct {
double x;
double y;
} point;

int main()
{
point A;
point B;
point C;
A . x=5;
A . y=4;
printf("Enter the X and Y for Point A:");
scanf ("%lg%lg", &A.x, &A.y);
printf("Enter the X and Y for Point B:");
scanf ("%lg%lg", &B.x, &B.y);
printf("Enter the X and Y for Point C:");
scanf ("%lg%lg", &C.x, &C.y);
printf ("The values entered for X and Y for Point A: %g\t %g\n",A.x,A.y);
printf("The values entered for X and Y for Point B: %g\t %g\n",B.x,B.y);
printf("The values entered for X and Y for Point C: %g\t %g\n",C.x,C.y);

return 0;
}
• 04-10-2003
Magos
//+----------------------------------------------
//| Magos' flame template v1.00
//+----------------------------------------------

Dear:

[ ] Sir
[ ] Lazy person
[X] Student with a program assignment
[ ] Rupert
[ ] Ugly naked guy

You are being flamed because:

[ ] You've shown an aggressive attitude towards someone in your post
[ ] You haven't search google for the answer you're looking for
[ ] You expect us to write an entire program for you
[X] You haven't shown enough effort in this assignment
[ ] You're a complete jerk
[ ] You want us to debug your entire buggy program for you
[ ] You lack valid arguments
[ ] You degraded my momma
[ ] You deny your own fault, blaming it on others

I suggest you:

[ ] Make a search on google
[ ] Read the forum rules/guidelines
[X] Make some further attempt to complete your assignment
[ ] Release your anger somewhere else
[X] Insert code tags around your code
[X] Try to isolate the problem, then post again

Finally, I'd also like to say:

[X] Fix the things above, and we'll be happy to help you next time
[X] Please, use code tags next time
[ ] Don't make a post like this again
[ ] Have a nice day!
[ ] Your momma is fat
• 04-10-2003
stumon
Quote:

[X] You momma is fat
--edit--
lol, i think he meant "your"
• 04-10-2003
naynay
What I was asking is not to do the homework, but to help with how to use char * classify triangle.
• 04-10-2003
stumon
>>char *
just means pointer to character. like

Code:

```char stringer[11] = {"Hey People"); char *stringerPtr = stringer; //now *stringer points to the address this string, actually, the address of the first element.```
• 04-10-2003
suezq
You guys are evil!
What do you mean about code tags? I put up a post before and I didn't have that. Anyways I think she is looking for a way to use the gets function instead of scanf. To put in the points and find out what kind of triangle it is. Which I have no idea how to. And why would you care if you helped write the code anyway, maybe you just don't know how to answer the problem and if that is the case then don't even reply back, people don't have time for that and stop trying to be so cute, you're trying too hard and it's not working Magos. : P
sue
• 04-10-2003
stumon
Please do not start posting throw backs at one another. He asked for help, we cant help until he gives us more information. All we see if scanf()'s, where is the beginning of the function that tells how to figure out what kind of triangle it is, its just a bunch of math to figure where the points are on a graph. No one is going to write all his code, he gives us what he has as far as that function and we help. Its that simple. Magos was just asking for more info in his own little way. ;)
--edit-- See:
Quote:

I suggest you:

[ ] Make a search on google
[ ] Read the forum rules/guidelines
[X] Make some further attempt to complete your assignment
[ ] Release your anger somewhere else
[X] Insert code tags around your code
[X] Try to isolate the problem, then post again
• 04-11-2003
Magos
Chill down, the flame template was meant as a joke.
Quote:

The problem I am having so far is how call to classify and determine which shape it is.
This was basically my point for posting that. You're telling us you have a problem with something, but not with what. You just posted the code where you enter the points for the triangle. Where are you stuck? What part don't you understand? Is it the formula for checking if a triangle is valid? Is it the formula -> code transformatin? Please be more specific, we are not mind readersyou know :).

If it's the formula, there is three cases: The shape is a point, a line or a triangle.

First, check if any of the points overlap (Xi = Xj & Yi = Yj for every point). If they do (if one do it's enough), it's not a triangle.

Second, if the points lie on a straight line it is not a triangle. To check this, calculate the slope between the lines and check if they are the same. if they are, it's not a triangle. (It's enough to just calculate two of the three slopes. If two of them are equal, the third has to be too).
To caluclate the slope, use K = (Yi - Yj) / (Xi - Xj).

Quote:

This concept must be 32978589275892728978972 years old.
Never said I invented it... :)

Quote:

What do you mean about code tags? I put up a post before and I didn't have that.
You should always use code tags when posting code (the exception would be one- or two-liners). Code tags have a purpose, you know. It makes the code easier to read, it indents properly, and every character have the same width.

Oh, and if you mean this post:
You were told to use code tags!

Quote:

Anyways I think she is looking for a way to use the gets function instead of scanf. To put in the points and find out what kind of triangle it is. Which I have no idea how to.
I don't know how you got that out of her (!) post, though I agree that gets is better than scanf. Oh, and you should use fgets, not gets. See the FAQ.

Quote:

And why would you care if you helped write the code anyway,
I usually don't mind writing code for others, as long as I find it interesting myself.

Quote:

maybe you just don't know how to answer the problem and if that is the case then don't even reply back, people don't have time for that
What can I say? Read the forum guidlines first. Too lazy to search? (Search? It's at the top of every page...), follow these links:
http://cboard.cprogramming.com/annou...p?s=&forumid=3