homework/cpp/myfuncStruct.cpp

30 lines
799 B
C++
Raw Normal View History

2024-05-22 17:33:42 +00:00
#include "myfuncStruct.h"
// Static function for string length calculation
static int my_strlen(const char *str) {
int length = 0;
while (str[length] != '\0') {
length++;
}
return length;
}
// Function to count occurrences of each character in 'alfabet' within 'slowo'
void count_charactersStruct(ZliczaczStruct* zliczacz) {
int alfabet_length = my_strlen(zliczacz->alfabet);
// Initialize the result array to zero
for (int i = 0; i < alfabet_length; ++i) {
zliczacz->wynik[i] = 0;
}
// Count occurrences
for (int i = 0; i < alfabet_length; ++i) {
for (int j = 0; zliczacz->slowo[j] != '\0'; ++j) {
if (zliczacz->alfabet[i] == zliczacz->slowo[j]) {
zliczacz->wynik[i]++;
}
}
}
}