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
- Lex program to find the Length of a String
- Program for length of a string using recursion
- 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
- 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.
- 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.