как сделать, чтобы strstr читал все строки, если у меня есть переводы строки \n?

Задание в том, что подается первая строчка, которую нужно найти в других строках, которые ниже и пометить перед вхождением "@". Как я понимаю, strstr читает только первую строку, а другие не хочет, поэтому работает некорректно.

Пример:

input.txt:

hello world
Welcome
 this is hello
world application
hello world  hello worl d  hello
world sample samples hello

output.txt:

Welcome
 this is @hello
world application
@hello world  hello worl d  @hello
world sample samples hello

что выводит у меня:

Welcome
 this is hello
world application
@hello world  hello worl d  hello
world sample samples hello
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

int main() {
    FILE* input_file = fopen("input.txt", "r");
    char word_phrase[100];
    fgets(word_phrase, sizeof(word_phrase), input_file);
    word_phrase[strcspn(word_phrase, "\n")] = '\0';  // Убираем символ новой строки, если он есть
    char text[2000];
    text[0] = '\0';
    char buffer[2000];
    while (fgets(buffer, sizeof(buffer), input_file) != NULL) {
        strcat(text, buffer);
    }
    fclose(input_file);

    // Поиск и замена всех вхождений
    char* pos = text;
    while ((pos = strstr(pos, word_phrase)) != NULL) {
        memmove(pos + 1, pos, strlen(pos) + 1);
        *pos = '@';
        pos += strlen(word_phrase) + 1;
    }

    // Запись результата в файл output.txt
    FILE* output_file = fopen("output.txt", "w");
    fprintf(output_file, "%s", text);
    fclose(output_file);
    return 0;
}

Ответы (0 шт):