funkcie
This commit is contained in:
parent
6bcb7fc73c
commit
27f3926b99
@ -33,6 +33,8 @@ add_executable(skola calc.c
|
||||
hviezdicky.h
|
||||
stringy.c
|
||||
stringy.h
|
||||
funkcie.c
|
||||
funkcie.h
|
||||
)
|
||||
|
||||
target_link_libraries(skola m)
|
||||
|
80
funkcie.c
Normal file
80
funkcie.c
Normal file
@ -0,0 +1,80 @@
|
||||
//
|
||||
// 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 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;
|
||||
}
|
2
funkcie.h
Normal file
2
funkcie.h
Normal file
@ -0,0 +1,2 @@
|
||||
int funkcie();
|
||||
int counterChars();
|
4
main.c
4
main.c
@ -1,5 +1,5 @@
|
||||
#include "stringy.h"
|
||||
#include "funkcie.h"
|
||||
|
||||
int main() {
|
||||
return stringy();
|
||||
return counterChars();
|
||||
}
|
Loading…
Reference in New Issue
Block a user