#include #include int is_word_starting_with_a(char first_char) { return (first_char == 'a' || first_char == 'A'); } void filterWordsStartingWithA(FILE *input_file, FILE *output_file) { char *line = NULL; size_t len = 0; ssize_t read; int inside_word = 0; while ((read = getline(&line, &len, input_file)) != -1) { for (int i = 0; line[i] != '\0'; i++) { if (line[i] == ' ' || line[i] == '\t' || line[i] == '\n') { // End of word, reset state inside_word = 0; } else { // Start of a new word if (!inside_word) { inside_word = 1; // Check if the word starts with 'a' if (is_word_starting_with_a(line[i])) { fprintf(output_file, "%c", line[i]); } } else { // Inside a word, continue writing characters fprintf(output_file, "%c", line[i]); } } } fprintf(output_file, "\n"); } free(line); } int main() { char input_file_path[] = "data.txt"; char output_file_path[] = "result.txt"; FILE *input_file = fopen(input_file_path, "r"); FILE *output_file = fopen(output_file_path, "w"); if (input_file == NULL || output_file == NULL) { perror("Error opening files"); return 1; } filterWordsStartingWithA(input_file, output_file); fclose(input_file); fclose(output_file); return 0; }