diff --git a/main.c b/main.c index c61aa66..3c53526 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,5 @@ #include "stringyreloaded.h" -int main() { - return volaco(); +int main(int argc, char *argv[]) { + return redirector(); } \ No newline at end of file diff --git a/myRand.h b/myRand.h index dbd45cd..d13d124 100644 --- a/myRand.h +++ b/myRand.h @@ -1 +1,2 @@ +#include "stdlib.h" int myrand(int min, int max); \ No newline at end of file diff --git a/stringyreloaded.c b/stringyreloaded.c index 7ecf841..35792cc 100644 --- a/stringyreloaded.c +++ b/stringyreloaded.c @@ -2,6 +2,7 @@ // Created by bruno on 3/18/24. // +#include #include "stringyreloaded.h" #include "curses.h" #include "string.h" @@ -88,7 +89,7 @@ int citanie() { return 0; } -int volaco() { +int cislovanie() { FILE *fp; char c; int pocet = 1; @@ -111,6 +112,106 @@ int volaco() { } while (!feof(fp)); fclose(fp); } else { - printf("s.txt neexistuje"); + printf("s.txt neexistuje."); + } + printf("Pozrite si súbor pismena2.txt"); + getch(); + return 0; +} + +int naVelke() { + FILE *fr, *fw; + int c; + if ((fw = fopen("pismena2.txt", "w")) == NULL) { + printf("pismena2.txt nejde otvoriť."); + return 1; + } + if ((fr = fopen("pismena.txt", "r")) == NULL) { + printf("pismena.txt nejde otvoriť."); + return 1; + } else { + while ((c = getc(fr)) != EOF) { + if (c >= 'a' && c <= 'z') { + putc(c + 'A' - 'a', fw); + } else { + putc(c, fw); + } + } + } + if (fclose(fw) == EOF) { + printf("Súbor pismena2.txt sa nezavrel."); + } + if (fclose(fr) == EOF) { + printf("Súbor pismena.txt sa nezavrel."); + } + printf("Pozrite si pismena2.txt"); + getch(); + return 0; +} + +int kopirovanie(int argc, char *argv[]) { + int c; + if (argc >= 3) { + FILE *fr, *fw; + if ((fr = fopen(argv[1], "r")) == NULL) { + printf("Súbor %s nejde otvoriť.", argv[1]); + return 1; + } + if ((fw = fopen(argv[2], "w")) == NULL) { + printf("Súbor %s nejde otvoriť.", argv[2]); + return 1; + } + while ((c = getc(fr)) != EOF) { + putc(c, fw); + } + if (fclose(fw) == EOF) { + printf("Súbor %s sa nezavrel.", argv[2]); + } + if (fclose(fr) == EOF) { + printf("Súbor %s sa nezavrel.", argv[1]); + } + printf("Skopírované, pozrite si %s", argv[2]); + getch(); + return 0; + } else { + printf("%s subor1 subor2", argv[0]); + return 1; } } + +int redirector() { + FILE *fw; + int c; + printf("Stlacte O pre vypis na obrazovku, \n" + "alebo iny znak pre zapis do suboru vystup.txt: "); + c = getchar(); + while (getchar() != '\n'); + if (c == 'o' || c == 'O') { + fw = stdout; + } else { + if (access("vystup.txt", F_OK) == 0) { + printf("Súbor vystup.txt už existuje, chcete ho prepísať? [A/N]"); + c = getchar(); + while (getchar() != '\n'); + if (!(c == 'a' || c == 'A')) { + return 0; + } + } + if ((fw = fopen("vystup.txt", "w")) == NULL) { + printf("Súbor vystup.txt sa nepodarilo otvoriť."); + return 1; + } + } + printf("Píšte niečo, ukončite hviezdičkou:"); + while ((c = getchar()) != '*') { + putc(c, fw); + } + if(fw != stdout) { + printf("Pozrite sa do vystup.txt"); + if(fclose(fw) == EOF) { + printf("Súbor vystup.txt sa nepodarilo zatvoriť."); + return 1; + } + } + return 0; +} \ No newline at end of file diff --git a/stringyreloaded.h b/stringyreloaded.h index 3fd0f91..8aa5502 100644 --- a/stringyreloaded.h +++ b/stringyreloaded.h @@ -2,4 +2,7 @@ int stringyreloaded(); int citanie(); int riadky(); int pridavanie(); -int volaco(); \ No newline at end of file +int cislovanie(); +int naVelke(); +int kopirovanie(int argc, char *argv[]); +int redirector(); \ No newline at end of file