Compare commits
6 Commits
01b776a5a9
...
master
Author | SHA1 | Date | |
---|---|---|---|
94539ee696 | |||
7cfd112572 | |||
a588e6d41b | |||
c631c7194c | |||
1422955906 | |||
27f3926b99 |
@@ -33,10 +33,11 @@ add_executable(skola calc.c
|
|||||||
hviezdicky.h
|
hviezdicky.h
|
||||||
stringy.c
|
stringy.c
|
||||||
stringy.h
|
stringy.h
|
||||||
hangman.c
|
funkcie.c
|
||||||
hangman.h
|
funkcie.h
|
||||||
termstuff.c
|
termstuff.c
|
||||||
termstuff.h
|
stringyreloaded.c
|
||||||
|
stringyreloaded.h
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(skola m)
|
target_link_libraries(skola m ncurses)
|
||||||
|
99
funkcie.c
Normal file
99
funkcie.c
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
//
|
||||||
|
// Created by bruno on 3/11/24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "funkcie.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
|
void greet(char meno[]) {
|
||||||
|
printf("Ahoj %s, vitaj na Adlerke.\n", meno);
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
greet("Viki");
|
||||||
|
int a = 10;
|
||||||
|
int b = 5;
|
||||||
|
printf("Zadaj strany obdĺžnika (a b):");
|
||||||
|
scanf("%d %d", &a, &b);
|
||||||
|
printf("Obdĺžnik so stranami %d a %d má obsah %d.\n", a, b, obsahObdlznika(a, b));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int containscharacter(char character, char characters[]) {
|
||||||
|
int i = 0;
|
||||||
|
while (characters[i]) {
|
||||||
|
if (character == characters[i]) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int jeCislo(char znak) {
|
||||||
|
return znak > 47 && znak < 58;
|
||||||
|
}
|
||||||
|
|
||||||
|
void toLowercase(char *instring) {
|
||||||
|
int i = 0;
|
||||||
|
while (instring[i] != '\n') {
|
||||||
|
if (instring[i] > 64 && instring[i] < 91) {
|
||||||
|
instring[i] += 32;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int counterChars() {
|
||||||
|
char instring[256];
|
||||||
|
printf("Zadaj max 255 znakový reťazec.");
|
||||||
|
fgets(instring, 255, stdin);
|
||||||
|
toLowercase(instring);
|
||||||
|
char samohlasky[] = "aeiou";
|
||||||
|
char spoluhlasky[] = "bmprsvzfhgkdtnlcj";
|
||||||
|
|
||||||
|
int cislaCnt = 0;
|
||||||
|
int samohlaskyCnt = 0;
|
||||||
|
int spoluhlaskyCnt = 0;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
while (instring[i] != '\n') {
|
||||||
|
if (jeCislo(instring[i])) {
|
||||||
|
cislaCnt++;
|
||||||
|
} else if (containscharacter(instring[i], samohlasky)) {
|
||||||
|
samohlaskyCnt++;
|
||||||
|
} else if (containscharacter(instring[i], spoluhlasky)) {
|
||||||
|
spoluhlaskyCnt++;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
printf("\"%s\" je dlhý %d znakov, %d z nich sú čísla, %d z nich sú samohlásky, %d z nich sú spoluhlásky a zvyšných je %d.\n",
|
||||||
|
instring, i, cislaCnt, samohlaskyCnt, spoluhlaskyCnt, i - cislaCnt - samohlaskyCnt - spoluhlaskyCnt);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
4
funkcie.h
Normal file
4
funkcie.h
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
int funkcie();
|
||||||
|
int counterChars();
|
||||||
|
int factorial(int cislo);
|
||||||
|
int facttest();
|
6
main.c
6
main.c
@@ -1,5 +1,5 @@
|
|||||||
#include "hangman.h"
|
#include "stringyreloaded.h"
|
||||||
|
|
||||||
int main() {
|
int main(int argc, char *argv[]) {
|
||||||
return hangman();
|
return input(argc, argv);
|
||||||
}
|
}
|
1
myRand.h
1
myRand.h
@@ -1 +1,2 @@
|
|||||||
|
#include "stdlib.h"
|
||||||
int myrand(int min, int max);
|
int myrand(int min, int max);
|
366
stringyreloaded.c
Normal file
366
stringyreloaded.c
Normal file
@@ -0,0 +1,366 @@
|
|||||||
|
//
|
||||||
|
// Created by bruno on 3/18/24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 cislovanie() {
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cislovanie2() {
|
||||||
|
FILE *fp;
|
||||||
|
char buf[25];
|
||||||
|
int index;
|
||||||
|
fp = fopen("s.txt", "w");
|
||||||
|
if (fp == NULL) {
|
||||||
|
printf("Chyba pri otváraní súboru");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
strcpy(buf, "Toto je riadok.");
|
||||||
|
for (index = 1; index <= 10; index++) {
|
||||||
|
fprintf(fp, "%s Číslo riadku %d\n", buf, index);
|
||||||
|
}
|
||||||
|
if (fclose(fp) == EOF) {
|
||||||
|
printf("Chyba pri zatváraní súboru.");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int appendovanie() {
|
||||||
|
FILE *fp;
|
||||||
|
char buf[35];
|
||||||
|
int index, count;
|
||||||
|
fp = fopen("s.txt", "a");
|
||||||
|
if (fp == NULL) {
|
||||||
|
printf("Chyba pri otváraní súboru");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
strcpy(buf, "Toto je riadok.");
|
||||||
|
for (count = 1; count <= 5; count++) {
|
||||||
|
for (index = 0; buf[index]; index++) {
|
||||||
|
putc(buf[index], fp);
|
||||||
|
putc('\n', fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fclose(fp) == EOF) {
|
||||||
|
printf("Chyba pri zatváraní súboru.");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int citanieSuboru() {
|
||||||
|
FILE *fp;
|
||||||
|
char c;
|
||||||
|
fp = fopen("s.txt", "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
printf("Chyba pri otváraní súboru");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
c = getc(fp);
|
||||||
|
putchar(c);
|
||||||
|
} while (c != EOF);
|
||||||
|
if (fclose(fp) == EOF) {
|
||||||
|
printf("Chyba pri zatváraní súboru.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int citanieSuboru2() {
|
||||||
|
FILE *fp;
|
||||||
|
char c;
|
||||||
|
int pocet = 1;
|
||||||
|
fp = fopen("s.txt", "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
printf("Chyba pri otváraní súboru");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
printf("\n%d: ", pocet);
|
||||||
|
do {
|
||||||
|
c = getc(fp);
|
||||||
|
if (c == '\n') {
|
||||||
|
if (feof(fp) == 0) {
|
||||||
|
c = getc(fp);
|
||||||
|
printf("\n%d: ", ++pocet);
|
||||||
|
ungetc(c, fp);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
putchar(c);
|
||||||
|
}
|
||||||
|
} while (c != EOF);
|
||||||
|
if (fclose(fp) == EOF) {
|
||||||
|
printf("Chyba pri zatváraní súboru.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int poSlovach() {
|
||||||
|
FILE *fp;
|
||||||
|
char slovo[100];
|
||||||
|
char c;
|
||||||
|
fp = fopen("s.txt", "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
printf("Nepodarilo sa otvoriť s.txt");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
c = fscanf(fp, "%s", slovo);
|
||||||
|
printf("%s\n", slovo);
|
||||||
|
} while (c != EOF);
|
||||||
|
fclose(fp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int poRiadkoch() {
|
||||||
|
FILE *fp;
|
||||||
|
char slovo[100];
|
||||||
|
char *c;
|
||||||
|
fp = fopen("s.txt", "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
printf("Nepodarilo sa otvoriť s.txt");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
c = fgets(slovo, 100, fp);
|
||||||
|
printf("%s\n", slovo);
|
||||||
|
} while (c != NULL);
|
||||||
|
fclose(fp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int input(int argc, char *argv[]) {
|
||||||
|
FILE *fp;
|
||||||
|
char slovo[100];
|
||||||
|
char *c;
|
||||||
|
if (argc == 1) {
|
||||||
|
printf("Použitie: %s filename\n", argv[0]);
|
||||||
|
} else {
|
||||||
|
if (argc > 2) {
|
||||||
|
printf("Spracuje sa len 1. parameter");
|
||||||
|
}
|
||||||
|
fp = fopen(argv[1], "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
printf("Nepodarilo sa otvoriť %s", argv[1]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
c = fgets(slovo, 100, fp);
|
||||||
|
if (c != NULL) {
|
||||||
|
printf("%s\n", slovo);
|
||||||
|
}
|
||||||
|
} while (c != NULL);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
15
stringyreloaded.h
Normal file
15
stringyreloaded.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
int stringyreloaded();
|
||||||
|
int citanie();
|
||||||
|
int riadky();
|
||||||
|
int pridavanie();
|
||||||
|
int cislovanie();
|
||||||
|
int naVelke();
|
||||||
|
int kopirovanie(int argc, char *argv[]);
|
||||||
|
int redirector();
|
||||||
|
int cislovanie2();
|
||||||
|
int appendovanie();
|
||||||
|
int citanieSuboru();
|
||||||
|
int citanieSuboru2();
|
||||||
|
int poSlovach();
|
||||||
|
int poRiadkoch();
|
||||||
|
int input(int argc, char *argv[]);
|
Reference in New Issue
Block a user