From a588e6d41bc1c47bb37214a2194e2a78ee24d80e Mon Sep 17 00:00:00 2001 From: bruno Date: Mon, 22 Apr 2024 16:04:50 +0200 Subject: [PATCH] volaco --- main.c | 2 +- stringyreloaded.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++- stringyreloaded.h | 6 +++- 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 1e8125c..c61aa66 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,5 @@ #include "stringyreloaded.h" int main() { - return stringyreloaded(); + return volaco(); } \ No newline at end of file diff --git a/stringyreloaded.c b/stringyreloaded.c index e980705..7ecf841 100644 --- a/stringyreloaded.c +++ b/stringyreloaded.c @@ -42,4 +42,75 @@ int stringyreloaded() { fputc('\n', fw); fclose(fw); return 0; -} \ No newline at end of file +} + +int riadky() { + FILE *fp; + char stuff[25]; + + fp = fopen("s.txt", "w"); + strcpy(stuff, "Toto je riadok"); + for (int index = 1; index <= 10; index++) { + fprintf(fp, "%s, riadok číslo %d.\n", stuff, index); + } + fclose(fp); + +} + +int pridavanie() { + FILE *fp; + char stuff[35]; + + fp = fopen("s.txt", "a"); + strcpy(stuff, "Toto je dalsi"); + for (int index = 0; stuff[index]; index++) { + putc(stuff[index], fp); + putc('\n', fp); + } + fclose(fp); + +} + +int citanie() { + FILE *fp; + char c; + fp = fopen("s.txt", "r"); + if (fp) { + do { + c = getc(fp); + if (c != EOF) { + putchar(c); + } + } while (c != EOF); + } else { + printf("s.txt neexistuje."); + } + return 0; +} + +int volaco() { + FILE *fp; + char c; + int pocet = 1; + fp = fopen("s.txt", "r"); + if (fp) { + printf("%d: ", pocet); + do { + c = getc(fp); + if (c == '\n') { + c = getc(fp); + if (!feof(fp)) { + printf("\n%d: ", ++pocet); + } + ungetc(c, fp); + } else { + if (!feof(fp)) { + putchar(c); + } + } + } while (!feof(fp)); + fclose(fp); + } else { + printf("s.txt neexistuje"); + } +} diff --git a/stringyreloaded.h b/stringyreloaded.h index 7209ff6..3fd0f91 100644 --- a/stringyreloaded.h +++ b/stringyreloaded.h @@ -1 +1,5 @@ -int stringyreloaded(); \ No newline at end of file +int stringyreloaded(); +int citanie(); +int riadky(); +int pridavanie(); +int volaco(); \ No newline at end of file