From c631c7194c4d66643dd4d8d1603de22f3af56417 Mon Sep 17 00:00:00 2001 From: bruno Date: Mon, 22 Apr 2024 15:16:41 +0200 Subject: [PATCH] nieco --- CMakeLists.txt | 5 ++++- funkcie.c | 19 +++++++++++++++++++ funkcie.h | 4 +++- main.c | 4 ++-- stringyreloaded.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ stringyreloaded.h | 1 + 6 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 stringyreloaded.c create mode 100644 stringyreloaded.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0640793..5087956 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,9 @@ add_executable(skola calc.c stringy.h funkcie.c funkcie.h + termstuff.c + stringyreloaded.c + stringyreloaded.h ) -target_link_libraries(skola m) +target_link_libraries(skola m ncurses) diff --git a/funkcie.c b/funkcie.c index fa0d476..3e85677 100644 --- a/funkcie.c +++ b/funkcie.c @@ -13,6 +13,14 @@ int obsahObdlznika(int w, int h) { return w * h; } +int factorial(int cislo) { + if(cislo == 1 || cislo == 0) { + return 1; + } else { + return cislo * factorial(cislo - 1); + } +} + int funkcie(void) { greet("Jožo"); greet("Fero"); @@ -78,3 +86,14 @@ int counterChars() { return 0; } + +int facttest() { + for (int i = 0 ; i < 11 ; i++){ + printf("%d: %d\n", i, factorial(i)); + } + int infact; + printf("Zadaj číslo: "); + scanf("%d", &infact); + printf("Factorial z %d je %d", infact, factorial(infact)); + return 0; +} \ No newline at end of file diff --git a/funkcie.h b/funkcie.h index 0362b7c..ba551d8 100644 --- a/funkcie.h +++ b/funkcie.h @@ -1,2 +1,4 @@ int funkcie(); -int counterChars(); \ No newline at end of file +int counterChars(); +int factorial(int cislo); +int facttest(); \ No newline at end of file diff --git a/main.c b/main.c index 9369030..1e8125c 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,5 @@ -#include "funkcie.h" +#include "stringyreloaded.h" int main() { - return counterChars(); + return stringyreloaded(); } \ No newline at end of file diff --git a/stringyreloaded.c b/stringyreloaded.c new file mode 100644 index 0000000..e980705 --- /dev/null +++ b/stringyreloaded.c @@ -0,0 +1,45 @@ +// +// Created by bruno on 3/18/24. +// + +#include "stringyreloaded.h" +#include "curses.h" +#include "string.h" + +int stringyreloaded() { + char meno[64]; + char adresa[64]; + char telefon[10]; + + char *s1 = "Ahoj"; + char s2[21]; + + FILE *fw; + fw = fopen("test.txt", "w"); + + strcpy(s2, "Hello"); + strcat(s2, " + "); + strcat(s2, s1); + + fprintf(fw, "Dĺžka reťazca %s je %lu.\n", s1, strlen(s1)); + fprintf(fw, "Dĺžka reťazca %s je %lu.\n", s2, strlen(s2)); + + + initscr(); + clear(); + puts("Zadaj meno a priezvisko: "); + getnstr(meno, 63); + puts("Zadaj adresu: "); + getnstr(adresa, 63); + puts("Zadaj telefón: "); + getnstr(telefon, 9); + fputs("Zadal si:\n", fw); + fputs(meno, fw); + fputc('\n', fw); + fputs(adresa, fw); + fputc('\n', fw); + fputs(telefon, fw); + fputc('\n', fw); + fclose(fw); + return 0; +} \ No newline at end of file diff --git a/stringyreloaded.h b/stringyreloaded.h new file mode 100644 index 0000000..7209ff6 --- /dev/null +++ b/stringyreloaded.h @@ -0,0 +1 @@ +int stringyreloaded(); \ No newline at end of file