This program processes a text file and outputs the formatted result to another file, modifying the content based on several conditions.
Purpose: Reads characters from input.txt and writes them to output.txt, applying transformations, spacing, and formatting. Key Functionalities: File Handling:
Opens input.txt for reading and output.txt for writing. Handles errors if files cannot be opened. Character Processing:
Converts lowercase letters to uppercase after punctuation marks (. ! ?). Replaces digits with *. Adds a space after punctuation marks unless the next character is a space. Line Formatting:
Maintains a fixed line length of 25 characters. Adds spaces to complete lines shorter than 25 characters. Appends a marker | c:X at the end of each line, where X is the number of characters read in that line. Special Conditions:
Skips carriage return characters (\r). Ensures proper handling of newline characters and spaces to avoid formatting errors. Summary: This program demonstrates:
File I/O: Reading from and writing to files. Character Handling: Using functions like isalpha, isdigit, and ispunct. Dynamic Formatting: Ensures fixed-width lines and applies transformations.