#include #define MAX_LINE_LENGTH 1000 int is_word_starting_with_a(const char *word) { return (word[0] == 'a' || word[0] == 'A'); } 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; } char line[MAX_LINE_LENGTH]; char word[MAX_LINE_LENGTH]; while (fgets(line, sizeof(line), input_file) != NULL) { int i = 0; int j = 0; while (line[i] != '\0') { if (line[i] == ' ' || line[i] == '\t' || line[i] == '\n') { // End of word, check and write to output if it starts with 'a' word[j] = '\0'; if (is_word_starting_with_a(word)) { fprintf(output_file, "%s ", word); } // Reset for the next word j = 0; } else { // Copy characters to the current word word[j++] = line[i]; } i++; } // Check and write the last word in the line word[j] = '\0'; if (is_word_starting_with_a(word)) { fprintf(output_file, "%s", word); } fprintf(output_file, "\n"); } fclose(input_file); fclose(output_file); return 0; }