{"id":300,"date":"2023-02-22T02:23:02","date_gmt":"2023-02-22T10:23:02","guid":{"rendered":"http:\/\/bitas.net.cn\/?page_id=300"},"modified":"2023-02-22T02:23:11","modified_gmt":"2023-02-22T10:23:11","slug":"105-2","status":"publish","type":"page","link":"http:\/\/bitas.net.cn\/index.php\/sourcecode\/105-2\/","title":{"rendered":"105 \u7528 list_head \u5b9e\u73b0\u5b66\u751f\u94fe\u8868"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h>\n#include \"linux_list.h\"\n\nLIST_HEAD(students);\n\ntypedef struct tagIDCard {\n    long serialNo;    \/\/ 6\u4f4d\u6570\u7684\u5e8f\u5217\u53f7\n    char name&#91;32];    \/\/ \u540d\u79f0\n} IDCard;\n\ntypedef struct tagStudent {\n    char gender;    \/\/ F or M\n    unsigned short age;\n    IDCard id; \n    struct list_head node;\n} Student;\n\nvoid print_student(Student *ps)\n{\n    if (ps) {\n        if (ps->id.serialNo &lt; 200000)\n            ps->id.serialNo += 200000;\n        printf(\"%15s: %c\\n\"\n                \"%15s: %hd\\n\"\n                \"%15s: %ld\\n\"\n                \"%15s: %s\\n\",\n                \"Gender\", ps->gender,\n                \"Age\", ps->age,\n                \"ID SerialNo.\", ps->id.serialNo,\n                \"ID name\", ps->id.name);\n        printf(\"-------------------------\\n\");\n    }   \n}\n\nint main(int argc, char *argv&#91;])\n{\n    Student s1 = { 'F', 20, { 200101, \"x1\" } };\n    Student s2 = { 'M', 21, { 200102, \"x2\" } };\n    Student s3 = { 'F', 22, { 200103, \"x3\" } };\n    list_add_tail(&amp;s1.node, &amp;students);\n    list_add_tail(&amp;s2.node, &amp;students);\n    list_add_tail(&amp;s3.node, &amp;students);\n    Student *ps, *n; \n    list_for_each_entry_safe(ps, n, &amp;students, node)\n        print_student(ps);\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":127,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-300","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/comments?post=300"}],"version-history":[{"count":1,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/300\/revisions"}],"predecessor-version":[{"id":301,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/300\/revisions\/301"}],"up":[{"embeddable":true,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/127"}],"wp:attachment":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/media?parent=300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}