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
- Print string of odd length in 'X' format
- Program for length of a string using recursion
- C program to find the length of a string
- Lex 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
- 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
- Find length of longest subsequence of one string which is substring of another string
- Minimum length of string having all permutation of given 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.