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
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Print string of odd length in 'X' format
- Java program to print Even length words in a String
- Program for length of a string using recursion
- Lex program to find the Length of a String
- C program to find the length of a string
- Program to print all substrings of a given string
- C Program to print all permutations of a given string
- Write a program to print all permutations of a given string
- Java Program to print distinct permutations of a string
- 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
- Construct a string of length L such that each substring of length X has exactly Y distinct letters
- Minimum length of the sub-string whose characters can be used to form a palindrome of length K
- C program to write an image in PGM format
- C program to invert (making negative) an image content in PGM format
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.