はじめての C

コード line.2 で 関数にポインタを使うよう プログラムを改造せよ。

  1. /* line.3 */
  2. #include
  3. struct Point {
  4. float x;
  5. float y;
  6. };
  7. struct Line {
  8. struct Point a, b;
  9. };
  10. struct Line func1(struct Line *);
  11. main()
  12. {
  13. struct Line line, *pline;
  14. pline = &line;
  15. func1(&line);
  16. printf("point a : (%f, %f)\n", pline->a.x, pline->a.y);
  17. printf("point b : (%f, %f)\n", pline->b.x, pline->b.y);
  18. }
  19. struct Line func1(struct Line *pline) {
  20. struct Line line;
  21. pline->a.x = 0.0;
  22. pline->a.y = 0.0;
  23. pline->b.x = 3.0;
  24. pline->b.y = 5.0;
  25. return line;
  26. }

(座標系上の三角形の面積を求めるプログラムは ↑の応用だろうけど ちょっとヤヤコシソー . . .)

text: 金山典世さん(稚内北星)のページ