Given string str. The task is to find the length of the string using %n format specifier
Input: Geeks For Geeks Output: 15 Input: Geeks Output: 5
To find the length of string, we use special format specifier “%n” in printf function. In C printf(), %n is a special format specifier which instead of printing something causes printf() to load the variable pointed by the corresponding argument with a value equal to the number of characters that have been printed by printf() before the occurrence of %n.
Below is the implementation of the above approach:
Geeks for Geeks = 15
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Print string of odd length in 'X' format
- Lexicographically smallest permutation of a string that can be reduced to length K by removing K-length prefixes from palindromic substrings of length 2K
- Java program to print Even length words in a String
- C program to invert (making negative) an image content in PGM format
- C program to write an image in PGM format
- Program to format a number with thousands separator in C/C++
- How to validate time in 12-hour format using Regular Expression
- How to validate time in 24-hour format using Regular Expression
- Minimum length of the sub-string whose characters can be used to form a palindrome of length K
- Construct a string of length L such that each substring of length X has exactly Y distinct letters
- Minimum length of Run Length Encoding possible by removing at most K characters from a given string
- Program for length of a string using recursion
- Print shortest path to print a string on screen
- Perform n steps to convert every digit of a number in the format [count][digit]
- Find the missing element in an array of integers represented in binary format
- C program to find the length of a string
- Lex program to find the Length of a String
- Find length of longest subsequence of one string which is substring of another string
- Minimum length of string having all permutation of given string.
- Check if a string contains a palindromic sub-string of even length
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.