Program to print last N lines in c++

In this tutorial, we will be discussing a program to print the last N lines.

For this, we will be provided with a string that consists of the new line character to denote the start of the next line and the number of lines to be printed from the last. Our task is to start from the last and print all the N lines counting from the last.

Example

#include 
using namespace std;
#define DELIM '\n'
//printing the last N lines
void print_last_lines(char *str, int n){
   if (n 

Output

str12
str13
str14
str15
str16
str17
str18
str19
str20
str21
str22
str23
str24
str25
Updated on: 2020-01-02T05:42:18+05:30

471 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements