{"id":827,"date":"2015-02-25T00:45:33","date_gmt":"2015-02-24T22:45:33","guid":{"rendered":"http:\/\/www.blue.pri.ee\/ttu\/?page_id=827"},"modified":"2026-01-21T21:52:12","modified_gmt":"2026-01-21T19:52:12","slug":"alamstruktuur","status":"publish","type":"page","link":"https:\/\/blue.pri.ee\/ttu\/programmeerimine-ii\/koodinaited\/alamstruktuur\/","title":{"rendered":"Alamstruktuuri kasutamine"},"content":{"rendered":"<p data-select-like-a-boss=\"1\">Struktuuride pesastamisel on oluline, et kompilaator oleks struktuuri liikmeka kasutatav andmet\u00fc\u00fcp juba &#8220;tuttav&#8221;. Seda saab teha kas lisades koodi t\u00e4ieliku struktuuri deklaratsiooni (nagu on tehtud j\u00e4rgnevas n\u00e4ites) v\u00f5i pakkudes struktuuri deklratsiooni (<em>forward declaration), <\/em>eeldusel, struktuuri sisu kirjeldus eksisteerib.<\/p>\n<pre class=\"lang:c decode:true \">\/**\r\n * File:         car_return.c\r\n * Author:       Risto Heinsar\r\n * Created:      02.02.2015\r\n * Modified      31.01.2025\r\n *\r\n * Description:  This is an example code showing creation of a nested struct\r\n *\/\r\n#include &lt;stdio.h&gt;\r\n#include &lt;string.h&gt;\r\n\r\n#define REG_LEN 8\r\n#define FIELD_LEN 32\r\n\r\nstruct Vehicle\r\n{\r\n    char make[FIELD_LEN];\r\n    char model[FIELD_LEN];\r\n};\r\n\r\nstruct CarRegistryEntry\r\n{\r\n    char regNum[REG_LEN];\r\n    char regCity[FIELD_LEN];\r\n    char owner[FIELD_LEN];\r\n    int year;\r\n    struct Vehicle car;\r\n};\r\n\r\nvoid PrintCar(struct CarRegistryEntry motor);\r\nvoid PrintCarUsingPtr(struct CarRegistryEntry *car);\r\n\r\nint main(void)\r\n{\r\n    struct CarRegistryEntry indestructibleHilux;\r\n    strcpy(indestructibleHilux.regNum,\"E473CJN\");\r\n    strcpy(indestructibleHilux.regCity,\"London\");\r\n    strcpy(indestructibleHilux.owner,\"The Stig\");\r\n    indestructibleHilux.year = 1988;\r\n    strcpy(indestructibleHilux.car.make,\"Toyota\");\r\n    strcpy(indestructibleHilux.car.model,\"Hilux\");\r\n\r\n    PrintCar(indestructibleHilux);\r\n    PrintCarUsingPtr(&amp;indestructibleHilux);\r\n\r\n    return 0;\r\n}\r\n\r\n\/**\r\n * Description:    Outputs the details of an automobile using . notation\r\n *\r\n * Parameters:     motor, vehicle structure with the details of a car\r\n *\r\n * Return:         none\r\n *\/\r\nvoid PrintCar(struct CarRegistryEntry motor)\r\n{\r\n    printf(\"%s %s, reg number %s, belongs to %s and is registered in %s\\n\",\r\n                                        motor.car.make, motor.car.model, \r\n                                        motor.regNum, motor.owner, \r\n                                        motor.regCity);\r\n}\r\n\r\n\/**\r\n * Description:    Outputs the details of an automobile using -&gt; notation\r\n *\r\n * Parameters:     motor, vehicle structure with the details of a car\r\n *\r\n * Return:         none\r\n *\/\r\nvoid PrintCarUsingPtr(struct CarRegistryEntry *motor)\r\n{\r\n    printf(\"%s %s, reg number %s, belongs to %s and is registered in %s\\n\",\r\n                                        motor-&gt;car.make, motor-&gt;car.model,\r\n                                        motor-&gt;regNum, motor-&gt;owner,\r\n                                        motor-&gt;regCity);\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Struktuuride pesastamisel on oluline, et kompilaator oleks struktuuri liikmeka kasutatav andmet\u00fc\u00fcp juba &#8220;tuttav&#8221;. Seda saab teha kas lisades koodi t\u00e4ieliku struktuuri deklaratsiooni (nagu on tehtud j\u00e4rgnevas n\u00e4ites) v\u00f5i pakkudes struktuuri deklratsiooni (forward declaration), eeldusel, struktuuri sisu kirjeldus eksisteerib. \/** * File: car_return.c * Author: Risto Heinsar * Created: 02.02.2015 * Modified 31.01.2025 * * Description: &hellip; <a href=\"https:\/\/blue.pri.ee\/ttu\/programmeerimine-ii\/koodinaited\/alamstruktuur\/\" class=\"more-link\">Loe edasi <span class=\"screen-reader-text\">Alamstruktuuri kasutamine<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":684,"menu_order":7,"comment_status":"closed","ping_status":"closed","template":"page-templates\/code-width.php","meta":{"footnotes":""},"class_list":["post-827","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages\/827","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/comments?post=827"}],"version-history":[{"count":5,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages\/827\/revisions"}],"predecessor-version":[{"id":11062,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages\/827\/revisions\/11062"}],"up":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages\/684"}],"wp:attachment":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/media?parent=827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}