From 6bcb7fc73c13c709218588259c22bee9b604ce63 Mon Sep 17 00:00:00 2001 From: bruno Date: Mon, 19 Feb 2024 15:56:12 +0100 Subject: [PATCH] obesenec --- stringy.c | 52 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/stringy.c b/stringy.c index 98fff02..731ef16 100644 --- a/stringy.c +++ b/stringy.c @@ -9,31 +9,53 @@ int meno() { scanf("%10s", str); strcpy(strkopia, str); char *acko = strchr(str, 'a'); - int poloha_acka = -1; + int polohaAcka = -1; if (acko) { - poloha_acka = acko - str; + polohaAcka = 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); + 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() { - 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++; + char word[21]; + char *p; + char tried[100]; + char *triedptr = tried; + printf("Zadaj slovo(max 20 znakov):"); + fgets(word, 20, stdin); + int unknownCharacterExists = 1; + while (unknownCharacterExists) { + printf("Zadaj znak:"); + 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; } \ No newline at end of file