Hello all, I am a beginner in C programming and have come up on a problem. I need to create 4 functions, 3 of the functions will get the users input (the 3 inputs will be the length of the sides of a triangle) and 1 function will be displaying what type of triangle it is (equilateral, isosceles or scalene)

Now this is my first time creating functions, I would know how to do use using traditional printf and scanf methods but my problem is that I need to create functions to get the input and display the answer such, the functions would named as so:
get_FirstLength, get_SecondLength, get_ThirdLength
and display_Message ( either equilateral, isosceles, scalene)

The material I have googled has been a little lacking as far as actual function creation and is more in depth about using pre made functions, is there anyone who can recommend me some reading about this type of function creation or can suggest a method for creating such functions.

Thank You

The trick is to keep in mind that C always passes parameters to functions by copy - the description "by value" or "by reference", is just an effect of copying either a value (like a variable), or an address (like a &value or array).

And remember that local variables from inside a function, go out of scope when the program returns. They die and go to variable heaven ;)

For your functions, since you can return one value, I'd return the length of the side, like so:

int getSide(void) {
  int length;
  printf("\n Enter the length of the side: ");
  scanf("%d", &length);
  getchar();     //pulls off vestige newline char on kboard buffer
  return length;

Then "catch" the return value:

int side1,side2, side3;
side1 = getSide();  
side2 = getSide();
side3 = getSide();

The value "length" from the function MAY still be available after the program returns from getSide() - C doesn't just "erase" variables like that - how long it stays "alive" is up to your compiler and OS. It can be over written, at any moment.

This article has been dead for over six months. Start a new discussion instead.