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
- Program to print all substrings of a given string
- Program to print Even Odd Number Pyramid
- Program to print all palindromes in a given range
- Program to print the initials of a name with the surname
- Program to print Step Pattern
- Program to print reciprocal of letters
- Write a program to print all permutations of a given 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
- 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 subsequences of a string
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.
Improved By : rituraj_jain