Category Archives: CN

C++ Program to Copy Text from One File to Another

File I/O is a fundamental skill in systems programming. This C++ program demonstrates how to copy the contents of one text file to another using standard C file functions: fopen(), fgetc(), fputc(), feof(), and fclose(). The program opens the source file in read mode and the destination file in write mode, then reads characters one at a time from the source and writes each character to the destination until the end of the source file is reached.

This approach is a classic example of character-level file copying — simple, portable, and easy to trace. It also shows basic error handling: if the source file cannot be opened (e.g., path does not exist), the program reports an error instead of proceeding.

Continue reading C++ Program to Copy Text from One File to Another

Implementation of Hamming Code in C++

The Hamming Code is an error-detection and error-correction technique developed by Richard Hamming. It introduces redundancy bits (also called parity bits) into a data frame at specific positions that are powers of 2 (positions 1, 2, 4, 8, …). Each redundancy bit covers a set of data bits determined by the binary representation of their positions. At the receiver’s end, the syndrome bits are recalculated and XOR-compared with the received parity bits — a non-zero result identifies the exact bit position where an error occurred.

This C++ program takes a data frame and the number of redundancy bits as input, inserts parity bits at the appropriate positions, simulates a single-bit error at a user-specified location, recalculates the syndrome, and reports the error position.

Continue reading Implementation of Hamming Code in C++