Given some text lines in one string, each line is separated by ‘\n’ character. Print the last N lines. If the number of lines is less than N, then print all lines.
An approach for this problem has been already discussed in Set-1 where only 10 lines were printed. In this post, another approach is discussed for printing the last N lines.
- Split the string around ‘\n’ using strtok.
- Store the individual strings in a vector.
- Print the last N strings from vector.
Below is the implementation of the above approach:
str16 str17 str18 str19 str20 str21 str22 str23 str24 str25
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Program to print reciprocal of letters
- Program to print all palindromes in a given range
- Program to print the given digit in words
- Program to print all substrings of a given string
- Program to print the initials of a name with the surname
- Program to print Even Odd Number Pyramid
- Program to print Step Pattern
- Write a program to print all permutations of a given string
- Java program to print Even length words in a String
- Java Program to print distinct permutations of a string
- C program to print the length of a String using %n format specifier
- Program to print characters present at prime indexes in a given string
- Program to print a doormat pattern having a string written in the center in Python
- Count of lines required to write the given String
- Print shortest path to print a string on screen
- Print all subarrays with 0 sum
- Print BST keys in the given range
- Print all interleavings of given two strings
- Print a pattern without using any loop
- Print Bracket Number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.