This commit is contained in:
Bruno Rybársky 2024-02-19 15:56:12 +01:00
parent ccb7b7018a
commit 6bcb7fc73c

@ -9,31 +9,53 @@ int meno() {
scanf("%10s", str); scanf("%10s", str);
strcpy(strkopia, str); strcpy(strkopia, str);
char *acko = strchr(str, 'a'); char *acko = strchr(str, 'a');
int poloha_acka = -1; int polohaAcka = -1;
if (acko) { if (acko) {
poloha_acka = acko - str; polohaAcka = acko - str;
} }
strcat(strkopia, " je tvoje meno"); strcat(strkopia, " je tvoje meno");
int dlzka = strlen(str); 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); printf("Kópia: %s, meno: %s ,dĺžka: %d, 'a' sa nachádza na: %d mieste v zadanom texte", strkopia, str, dlzka,
polohaAcka);
} }
int stringy() { int stringy() {
char str[21]; char word[21];
printf("Zadaj vetu(max 20 znakov):"); char *p;
fgets(str, 20, stdin); char tried[100];
printf("Zadaj znak:"); char *triedptr = tried;
char needle = getchar(); printf("Zadaj slovo(max 20 znakov):");
int strlocation = 0; fgets(word, 20, stdin);
int needlecount = 0; int unknownCharacterExists = 1;
while (str[strlocation] != 0){ while (unknownCharacterExists) {
if(str[strlocation] == needle){ printf("Zadaj znak:");
needlecount++; char znak = '\n';
while (znak == '\n'){
znak = getchar();
} }
strlocation++; *triedptr = znak;
triedptr++;
p = word;
int characterFound;
unknownCharacterExists = 0;
while (*p != '\n') {
characterFound = 0;
for (char *triedFindptr = tried; *triedFindptr != 0; triedFindptr++) {
if (*p == *triedFindptr) {
putchar(*p);
characterFound = 1;
break;
}
}
if (!characterFound) {
putchar('_');
unknownCharacterExists = 1;
}
p++;
}
putchar('\n');
} }
printf("%c sa v %s nachádza %d krát.", needle, str, needlecount);
return 0; return 0;
} }