はじめての C
コード line.2 で 関数にポインタを使うよう プログラムを改造せよ。
- /* line.3 */
- #include
- struct Point {
- float x;
- float y;
- };
- struct Line {
- struct Point a, b;
- };
- struct Line func1(struct Line *);
- main()
- {
- struct Line line, *pline;
- pline = &line;
- func1(&line);
- printf("point a : (%f, %f)\n", pline->a.x, pline->a.y);
- printf("point b : (%f, %f)\n", pline->b.x, pline->b.y);
- }
- struct Line func1(struct Line *pline) {
- struct Line line;
- pline->a.x = 0.0;
- pline->a.y = 0.0;
- pline->b.x = 3.0;
- pline->b.y = 5.0;
- return line;
- }
(座標系上の三角形の面積を求めるプログラムは ↑の応用だろうけど ちょっとヤヤコシソー . . .)
text: 金山典世さん(稚内北星)のページ