Добавил:
Рад, если кому-то помог Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
2
Добавлен:
01.11.2025
Размер:
716 б
Скачать
#include <stdio.h>
#include <string.h>

int countSubstring(const char *str, const char *sub) {
    int count = 0;
    int sub_len = strlen(sub);
    const char *pos = str;
    
    while ((pos = strstr(pos, sub)) != NULL) {
        count++;
        pos += sub_len;
    }
    return count;
}

int main() {
    char input[1000];
    
    printf("Enter a string: ");
    fgets(input, sizeof(input), stdin);
    input[strcspn(input, "\n")] = '\0';
    
    const char *substring = "ABBA";
    int occurrences = countSubstring(input, substring);
    
    printf("String: \"%s\"\n", input);
    printf("The substring \"%s\" appears %d time(s).\n", substring, occurrences);
    
    return 0;
}
Соседние файлы в папке Лаба6