From 2b3d65c582d260c69d7434f16946644dfa7eaf83 Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Fri, 31 Jul 2020 21:55:25 +0700 Subject: [PATCH] Add linked list function and example code Updated for read file function --- tests/work1 | Bin 16568 -> 16832 bytes tests/work1.c | 37 +++++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/tests/work1 b/tests/work1 index d1f9c9dae5c7cc1dd01256fb9cb3b446601ae52d..ef6286ba16e9857cfe7f30b8ef5d8c8293e46f22 100755 GIT binary patch delta 3042 zcmZ8jZBQG>8QwbykgyFBpbEt_9CevsC!8d}fcYpVgPbF!R1C(kJ8@+hNreUw15&~t zSJGe--(Vb(t!LUyGvofrByBoFLuP{e!$9anU*C7{ zPGA%WhEoVr_AXuHjoBo2wl+0{%LLiQ!QL{!I7u(_AHTm1NgwWwHJ zc^<3@$t*n!Ll}^20|4^$W|6G?>xKPGD9JM`ar^0I6x8*o;c$AbxKbk90j{AwAg4cL z0ahQHAb?E&VtcGcb1beTr`N!{i;z^i6^1|(_5rZj7=wYI{vhv5kvi=S`RUsWAkkiX z!``cP^$mv`o0^HNSm-7DA*b)5s>*ZzE3)#zvRRM_8{Ni}^iOt2(t%pme}@e?>)+6E z9dQ}g(}oEx6#pH0?(#UKWX@Od-N?${?#jQEl?MthPrq-LmpWskus$LavND5~a&~44 z03&7nDGko!9B2I(@YQ7f7x^T^48Do1|HmlGOZ}nIvoUNbGXX8kNh8e68NDShdF$Y> zfmwxtjAmy>m?qD{P-odtWhEd$69)m!8hLgg1?U010N4zeNkT)K9r%e7kab6vQn7&_ zW(C;-O-u_-+wA2bXeoj6;`c6Nx~LMU(EJ8AKo77s%(9T1<@dJ06NfatQik(ipHp5( zC82sSTQL#Le^Gmuw`cx>s=D)9GH@3cFgWZ&&?E&F}|9c4u z`|{6nac+X=r?%yHa>ObS8F1TP=&+D+@A#hWnQQ;{K|*{dx|P3v-8ay!eBnFpQ?>@= zx!N}1`+E-l55{lV==f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o%3g;{x*L8hx-o8PB17g@#xRrtPVz}Y6worI`dn8Ju2Qbj6-7$fSX8OMNWcY|C23eQ1}K5#n%aM zay^YT-1iN&b>^(Mkq)fFZ~k45@9?%CpKY(iTRvnZ^VA_>M;HdHt($28nq?nXc0q?c z6!hB6Q1!WG%Qu#WIZ?}ZngV19uFBoi3l7C6CV4Zr){056Ls2M!oZ_Q*U@`C*WbDI0 z13tJMY=9)kLo!gp+{J*0Msal8YDn3@TEgbLZMYnW2R&2*G3d5ANfKTOK1)@Y47&Ms z1WW!lC}WVed1wYlH^^-h=+B}bz|jrMZF|Kr>+D-qk&O@xdHgcE9BCw^x))ZMZ89az zBmmY+0jRf@|A7qwg_&To^n3%!ZATkn4y7E-bnx z>xxlNBN?%_sk*LXmQMB4X>=!QEFjNx)~@TiIX_I;_lB9#oQOYSfR(#8;Ukv7)uWnP z`KP^u)})7D%I33>iXLrBr`hK)edyHbbnbXA56jVQ_38Bf=X%nK=X=xXinb$4v4iX| z)^U+;0)MCC@Y+=NRN{q!&WKp;(TkO?#tjH_r9%RK)6U zLz2w7F~}mDkyOLYSnLvHyM2|Jof*o~RK-zk3ke3)h@-l%0l1)cW8eRzc02k5rXT@- ZJmTzcH@#md9E`U+Vo}q*4U-+d{{UbXhTQ-F diff --git a/tests/work1.c b/tests/work1.c index 29b9140..6d4fe5d 100644 --- a/tests/work1.c +++ b/tests/work1.c @@ -1,5 +1,6 @@ #include "stdio.h" #include "string.h" +#include "stdlib.h" struct person_tag { @@ -37,29 +38,40 @@ int main() printf("Hello, %s \n", person2.name); printf("Hello Ptr, %s \n", personPtr->name); - // using linkedlist - struct student_tag* first = NULL; - struct student_tag* second = NULL; - struct student_tag* third = NULL; + struct student_tag *first = NULL; + struct student_tag *second = NULL; + struct student_tag *third = NULL; - struct course_tag c1 = { "Computer", 4 }; - struct person_tag p1 = { "Sambo", "121214" }; + first = (struct student_tage *)malloc(sizeof(struct student_tag *)); + + struct course_tag c1 = {"Computer", 4, {1, 2, 3, 4}}; + struct person_tag p1 = {"Sambo", "121214"}; first->course_info = c1; first->student_info = p1; - + first->next = second; + + printf("Student name: %s \n", first->student_info.name); + printf("Student id: %s \n", first->student_info.id); + printf("Course name: %s \n", first->course_info.course_name); + printf("Course of units: %d", first->course_info.no_of_units); + printf("%d", first->course_info.marks); return 0; } -void read_file() { +void read_file() +{ // read the file here... FILE *file; char c; - if ((file = fopen("./../data/welcome.txt", "r")) == NULL) { + if ((file = fopen("./../data/welcome.txt", "r")) == NULL) + { printf("no file were found...!"); - } else { + } + else + { while ((c = getc(file)) != EOF) { printf("%c", c); @@ -67,14 +79,15 @@ void read_file() { } } -void menu(int menu) { +void menu(int menu) +{ // do something here... switch (menu) { case 1: printf("1. Student details..."); break; - + default: printf("No menu found here...!"); break;