Programming contests

20 Programming Exercise for Beginners

January 1, 2019 12:00 AM – December 31, 2019 12:00 AM

Linux TAC command

On Unix-like operating systems, the tac command prints the contents of the standard input, in reverse, line by line. Create a program that provides the same functionality.

Input Specification

The input is an ASCII text without any restrictions.

Sample Input

  1. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  2. Aenean ultrices bibendum mollis.
download as text file

Output Specification

Output for Sample Input

  1. Aenean ultrices bibendum mollis.
  2. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
download as text file

Hints and Guide

Because of the length of input line was not specified, the best solution is to create a linked list to store the characters of the current line. Instead of reading individual characters, we recommend to use a buffer filled with the help of the fgets function.

Printing the output in reverse order, line by line, can be easily done with recursion.

One possible solution is available in: main.c.

Acknowledgement This work was supported by the construction EFOP-3.4.3-16-2016-00021. The project was supported by the European Union, co-financed by the European Social Fund.
University of Debrecen; Faculty of Informatics; v. 03/01/2019