Question: Write a program in C++ that does the following: 1. It doesn't use a call from any C or C++ library including cout, cin, printf,

Write a program in C++ that does the following:

1. It doesn't use a call from any C or C++ library including cout, cin, printf, scanf, etc. Instead, it uses system calls such as open(), close(), read(), write(), and lseek().

2. It takes a file as a command line argument. It then reads the file from top to bottom and bottom to top simultaneously.

3. If a character being read in the first part is the same as a character being read in the second part, a 0 is printed out. Else, a 1 is printed out.

4. Then for each pair of differing characters, it prints out the position number of the first character, the differing characters, and a new line.

5. Finally, it prints out the number of character positions that differ.

For example, suppose the input file has the text "abcdefdcbx"

Then the following is printed out:

100011001

1 a x

5 e f

6 f e

10 x a

Total: 4 character positions differ

NOTE: Don't copy and paste from other sources. Make sure all the requirements of the program are fulfilled.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!