From 179c7b82c0c979c040ea8ed35b124aa468cefdb1 Mon Sep 17 00:00:00 2001 From: landrin Date: Tue, 15 Oct 2024 11:33:30 +0200 Subject: [PATCH] Dylan Landrin add save file --- exependu | Bin 0 -> 17456 bytes pendu.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ save_party.txt | 4 ++++ 3 files changed, 54 insertions(+) create mode 100755 exependu create mode 100644 save_party.txt diff --git a/exependu b/exependu new file mode 100755 index 0000000000000000000000000000000000000000..b937f2ad5e327acea572cccfc32b533be93458ff GIT binary patch literal 17456 zcmeHPeQ*@VmG9L`AQM;#2W*T#7>Kz-30lOr0AsX5D@KVhGDrqj49l`Rk~XY%<=t5W zK8WEqcGwd#x`f>65?7tbxe}=RB3BoVP?Z>vW4Mppfs3R_*}f<)JC=;i3E57F1K#_+ znSP_$(Qcf|-5-}KwU~YVe*NC-?$_Nj)6?BNGboaW-ebaoDVLBa=@kmwCz&ZsMY+k7 zUI|4d@1%ZNFs7Vt<)@G`f@1tyv_}?(sa=nJ(^P57H?7X4HL~8Sq^w8oBE9WWZ@biE zI!pyZV9NfaV$fAB?K!D}GzyCGD}+;Ti_~+{Iw{YT@}RKkO+Ebk{YS`zKTBUa=q=*|BWNf@ruh8i}QLSMIJ}R=I46HyQUX zGKxUuqCBWit$V0Nz|0xKxH&04P4bk!=DuCqw10Si@ti(w>h*tms{R|l`0O{>2IWaI z6i8nd$>1seNn9jj*8hNk6Gq{Z_8%Q)EdTGf04sTtHUg7FJSTN?0o-2zf3N`lM+NZZ z1@MOp;GZji>jm&n6u{2`S8zE)J%D_Em|6h8vjD!W0DcL$g3B2u1IU-J27HcFn0WNZ z5Ou$0BAE!r!lE_asl`Mf5J|>ED^>)OpY?4iKx-rxj7FX$mNF%i2|dsejKsvc#)jIp zfkocsR&0qCTjX6T0u9aU17R(pwMCM;mS|qTHX4s<&A}Z}vewoSk4b9*Q#7xjQTrl{ z0{U}HN^u$)MYzjxj09bfaDno8zcUh$)URq0Zd;gbl|4v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@+qBU}t7~5VKq&z<#Ig3|}$k_gK z&9F1JeQWW&Datc0iczuKsa@m)h@YR+fGeDtjoviyvHj$)4LdeL8La|dF76uBf0h@J zr*AfnrZOyf2rn8tzP1&RPZYqPEr5Ts0RG(q_=N)aTLthBfs-Gc<7*0J zMRy73bLvxslZT{IvDBq+b@}|Z$dJEFC^e>Fri2&Xza z_CUqP1t6*Ch~m%;z7>ZcR=?4=-XHKkR2RTulw85E2-H3LkZ*m%+T0Z5Bn%)N)(ZGl zX+f>qC<5ymH`MwX0~_k=H~E_b&A!@3KUp=-&xDdGqsYJgbc_}b>OpxPr>2Gv+R&jI z1o|4M7AiT*v9eQvFsGcxsJI8Pm zOG|VLZ!E5B-nLlEi#0baUFdsk(2i6DM-C%l3HfRpD)nHSFvQz~$#&rl?};G`lj;dG zKYb%yfm~R9XC3oS8JDp zsXYv9%$YXKQDtgy99acBA~0sEqveDbBidO1v)wcPH&J@S!Yv2SZZq)vJyV_!%Va~A z<3#B-l3txzpXUKg6{OiishvT587{m27CA3q>U{0t=MkG}aOm^Af~mrSk~;M_1OFxF zuw4E=nLks`pXd3`@&}<$b9~n4c?#13axMbZk)o{6^YI8U%98bYKEss1BS6Fm(j2qm zal~kj&iXv>VLDGra`{<~=@*esbAIM|e#Ep!>O0FXVbP5U`IPmoc@!xi@OKE#-&y~^ zfDGx^k}v|#x0v#G5Yi`~IrWbMBcHH+yeybOQs)f9+5XQt^cAVcbXb~W;xI41?a=3W zo<&(vQm6h2hd$2-nGSr6{`VaE{QksrspS~c5a-Wk&3VD7|9F1Ml)tC3ywiU_l=)lj zuSiKr->?!)oZC-Ii60?C?Z;v~UuD|Nf|5G(r+JE9pXaqqw@{)jIP-rKX*5Ta!`_#a-^+k=8t} NRi?yDhk}C@{{vpDlso_c literal 0 HcmV?d00001 diff --git a/pendu.c b/pendu.c index 1b0cfd6..7bf2146 100644 --- a/pendu.c +++ b/pendu.c @@ -35,6 +35,50 @@ void display_hangman(int tries) { } } +/* +this function allow to save a last party + +Parameters: + status -> state that save if the gamer win or lose the party + good_word -> the word to guess +*/ +void save_party(char * status, const char * good_word, char try[]) { + time_t t; + time(&t); //stock the current time + char * date; + date = ctime(&t); //stock the current time format as: day, month, number of the month, hour, year + + /* for (int i = 0; i < sizeof(try); i++) { + printf("%c",try[i]); + }*/ + + FILE* fichier = fopen("save_party.txt", "w"); + + if (fichier != NULL) + { + fputs("Date and time: ", fichier); + fputs(date,fichier); + fputs("\n",fichier); + + fputs("Status: ", fichier); + fputs(status,fichier); + fputs("\n",fichier); + + fputs("Good word: ", fichier); + fputs(good_word,fichier); + fputs("\n",fichier); + + /*fputs("tried letters: ", fichier); + for (int i = 0; i < sizeof(try); i++) { + fputs(try[i],fichier); + } + fputc("\n",fichier);*/ + + fclose(fichier); // On ferme le fichier qui a été ouvert + } + +} + int main() { srand(time(NULL)); const char *word = words[rand() % MAX_WORDS]; @@ -42,6 +86,7 @@ int main() { char guessed[word_length]; int tries = 0; int guessed_correctly = 0; + char try[MAX_TRIES]; //save the carcater try for (int i = 0; i < word_length; i++) { guessed[i] = '_'; @@ -54,6 +99,9 @@ int main() { char guess; printf("Entrez une lettre : "); scanf(" %c", &guess); + + try[tries] = guess; + int found = 0; for (int i = 0; i < word_length; i++) { @@ -73,9 +121,11 @@ int main() { if (guessed_correctly == word_length) { printf("Félicitations ! Vous avez deviné le mot : %s\n", word); + save_party("Win", word, try); } else { printf("Désolé, vous avez perdu. Le mot était : %s\n", word); display_hangman(MAX_TRIES); + save_party("Lose", word, try); } return 0; diff --git a/save_party.txt b/save_party.txt new file mode 100644 index 0000000..797beb6 --- /dev/null +++ b/save_party.txt @@ -0,0 +1,4 @@ +Date and time: Tue Oct 15 11:30:44 2024 + +Status: Lose +Good word: jeu