obesenec
This commit is contained in:
parent
ccb7b7018a
commit
6bcb7fc73c
52
stringy.c
52
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user