String
This commit is contained in:
parent
55739d0c56
commit
ccb7b7018a
@ -31,6 +31,8 @@ add_executable(skola calc.c
|
||||
myRand.c
|
||||
hviezdicky.c
|
||||
hviezdicky.h
|
||||
stringy.c
|
||||
stringy.h
|
||||
)
|
||||
|
||||
target_link_libraries(skola m)
|
||||
|
4
main.c
4
main.c
@ -1,5 +1,5 @@
|
||||
#include "hviezdicky.h"
|
||||
#include "stringy.h"
|
||||
|
||||
int main() {
|
||||
return stars();
|
||||
return stringy();
|
||||
}
|
39
stringy.c
Normal file
39
stringy.c
Normal file
@ -0,0 +1,39 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "stringy.h"
|
||||
|
||||
int meno() {
|
||||
char str[11];
|
||||
char strkopia[25];
|
||||
printf("Zadaj meno(max 10 znakov):");
|
||||
scanf("%10s", str);
|
||||
strcpy(strkopia, str);
|
||||
char *acko = strchr(str, 'a');
|
||||
int poloha_acka = -1;
|
||||
if (acko) {
|
||||
poloha_acka = acko - str;
|
||||
}
|
||||
strcat(strkopia, " je tvoje meno");
|
||||
int dlzka = strlen(str);
|
||||
printf("Kópia: %s, meno: %s ,dĺžka: %d, 'a' sa nachádza na: %d mieste v zadanom texte", strkopia, str, dlzka, poloha_acka);
|
||||
|
||||
}
|
||||
|
||||
int stringy() {
|
||||
char str[21];
|
||||
printf("Zadaj vetu(max 20 znakov):");
|
||||
fgets(str, 20, stdin);
|
||||
printf("Zadaj znak:");
|
||||
char needle = getchar();
|
||||
int strlocation = 0;
|
||||
int needlecount = 0;
|
||||
while (str[strlocation] != 0){
|
||||
if(str[strlocation] == needle){
|
||||
needlecount++;
|
||||
}
|
||||
strlocation++;
|
||||
}
|
||||
printf("%c sa v %s nachádza %d krát.", needle, str, needlecount);
|
||||
|
||||
return 0;
|
||||
}
|
2
stringy.h
Normal file
2
stringy.h
Normal file
@ -0,0 +1,2 @@
|
||||
int stringy();
|
||||
|
Loading…
Reference in New Issue
Block a user